Cross compiling for arm or aarch64 on Debian or Ubuntu

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024
  • In this video I'll explain how to do cross compiling for arm or aarch64 on Debian or Ubuntu. To make the resulting binaries portable, I'll also cover static linking.
    It’s not always possible to build directly ARM-based devices, especially when they are limited in resources. The majority of build and developer machines are still on x86 and by using a cross compiler, it is possible to build binaries or executables usable on another architecture. For example, to use your standard PC, most likely x86, to build something that is usable on another machine or device that’s on another architecture, for example 32 bit or 64 bit ARM.
    Contents:
    - Theoretical explanation for cross compilation
    - Cross compile of a basic C program for ARM aarch64
    - Cross compilation with configure and make (strace)
    - Static linking and advantages/disadvantages
    - Cross compiling for ARM using musl (tcpdump).
    All info discussed and shown in the video can be found well-documented on my blog, jensd.be, as well. For this video: jensd.be/1126/...

ความคิดเห็น • 61

  • @crypticcrypto7689
    @crypticcrypto7689 2 ปีที่แล้ว +13

    One of the most concise, to the point, knowledge-packed video on YT. Thanks heaps man!

    • @jurgenvanimpe6465
      @jurgenvanimpe6465 9 หลายเดือนก่อน

      Fully agree! Exactly what I needed to understand this :)

  • @Kasas90
    @Kasas90 3 ปีที่แล้ว +5

    YOU NAILED IT. Spent literally days to move from theory to practice, and you have just smashed it, just like that, making me feel like a noob. Liked and subscribed bro.

    • @jensdbe
      @jensdbe  3 ปีที่แล้ว

      Thanks a lot for the nice feedback, makes it worth spending time on this :)

  • @nazgulsenpai
    @nazgulsenpai 3 ปีที่แล้ว +5

    This is exactly what I needed. Building directly on the PinePhone is a pain for larger projects. I knew there had to be a better way!

    • @jensdbe
      @jensdbe  3 ปีที่แล้ว +1

      Good to hear this helped you!

  • @kamleshgandhi6042
    @kamleshgandhi6042 5 หลายเดือนก่อน +1

    I had been struggling to cross-compile my application for NXP/Freescale i.mx6ul processor. Your article and video provided all the clarifications needed to actually build and copy executable on target machine and simply run it. Many thanks once again.

  • @digicyc
    @digicyc 2 ปีที่แล้ว +3

    For even my hello-world I had to pass in -static to get it to run. Great video!

    • @jensdbe
      @jensdbe  2 ปีที่แล้ว

      Thanks!

  • @davidbrooks5269
    @davidbrooks5269 2 ปีที่แล้ว +3

    Great video - direct, and to the point. I stopped it multiple times and replicated the steps on my systems to insure I understood. Everything functioned exactly as shown. Thanks again.

  • @nonix3470
    @nonix3470 ปีที่แล้ว +2

    very nice simple and easy to understand with an avarage knowledge

  • @noodlish
    @noodlish 3 ปีที่แล้ว +5

    Thanks for the excellent introduction. My case is needing aarch64 native extensions for Ruby but built on x86_64, since that's all we have for CI build hosts.

  • @zameerahmed7369
    @zameerahmed7369 ปีที่แล้ว +2

    Ur explanation was awesome ..............

  • @ozgurayik7181
    @ozgurayik7181 2 หลายเดือนก่อน

    Well explained. I wish to see a few more videos on same topic. For example : cross compiling by connecting host machine's root directory by using sshfs and maybe even more practical example with cmake projects. Thanks for informative video .

  • @system7669
    @system7669 2 ปีที่แล้ว +2

    This video really cleared all of my doubts. Nice work 👍

  • @Santosamapaio
    @Santosamapaio 2 ปีที่แล้ว +2

    Job well done!! This is the best video about the topic! Thanks for sharing

  • @robotisim
    @robotisim 2 ปีที่แล้ว +2

    You just solved a question i had for years .Thank YOU !

    • @jensdbe
      @jensdbe  2 ปีที่แล้ว

      Great to hear!

  • @horaciomlhh
    @horaciomlhh 3 ปีที่แล้ว +2

    Very straightforward! thanks

    • @jensdbe
      @jensdbe  3 ปีที่แล้ว

      Thanks for the positive feedback :)

  • @PhalzuBG
    @PhalzuBG 4 หลายเดือนก่อน

    Thanks, this is a really good explanation of how cross-compiling works and what you should notice by doing so!~

    • @jensdbe
      @jensdbe  4 หลายเดือนก่อน

      Thanks, glad it was helpful!

  • @juliandavidarroyavezuluaga1851
    @juliandavidarroyavezuluaga1851 3 ปีที่แล้ว +2

    It was a really good explanation! thanks a lot!

    • @jensdbe
      @jensdbe  3 ปีที่แล้ว

      Thanks a lot for the nice feedback, good to hear you liked the video :)

  • @abdulbary3668
    @abdulbary3668 ปีที่แล้ว +2

    Thank you so much. You saved me

  • @Sunil-yz7ig
    @Sunil-yz7ig 2 ปีที่แล้ว +2

    Great explanation.
    I want to do dynamic linking for my application and my libraries at host machine.
    Can someone point me on how to do this? How to find all dependency of my application, group all of them together at build machine. Later at run time at host, provide proper runtime environment variable to correctly run the application.
    Looking forward to responses.

  • @AshLucieas-vs6xl
    @AshLucieas-vs6xl 2 หลายเดือนก่อน +1

    Love this ❤

  • @esjay3562
    @esjay3562 ปีที่แล้ว +2

    Generally, works fine except for big endian. When using option '-mbig-endian' it's only possible to compile object files. When building shared libraries or ELF files, error "libstdc++.so (wrong file format)" is issued. It seems the linker tries to use the little-endian version of the .so file.

  • @MikeSutton-ho8pc
    @MikeSutton-ho8pc หลายเดือนก่อน

    Enjoyed your training video. Have you ever tried to run a source-code security scan, like Fortify SCA for example, on a Linux Cross-Compiler-based software project?

  • @user-lw5ep2xn3u
    @user-lw5ep2xn3u 2 ปีที่แล้ว +2

    Very clear! Is it possiable to do the dynamic linking?

    • @jensdbe
      @jensdbe  2 ปีที่แล้ว

      Sure, that's the default, so if you don't pass the -static compiler flag, it should use dynamic linking

    • @user-lw5ep2xn3u
      @user-lw5ep2xn3u 2 ปีที่แล้ว

      @@jensdbe Thanks for your reply. Is it possiable to install the required arm64 libraries on a amd64 Ubuntu Computer.So I can cross-compile my own library to arm64.

  • @javeshbhardwaj
    @javeshbhardwaj 3 ปีที่แล้ว +1

    Thank you for the nice video.But i am unable to compile c++ code, the arm c++ compiler throws the error "fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory". Any idea how can i get through?Thanks again.

  • @manikantakumar2896
    @manikantakumar2896 3 ปีที่แล้ว +1

    i used this method ,while cross compilation it displays fatal error linux/init.h not found ,plz tell how to fix it

  • @carlosmartins00098
    @carlosmartins00098 ปีที่แล้ว +1

    Muito obrigado por ensinar como complilar para arm, eu estou tentando instalar o yay(aur) no termux e não sei se o yay funciona fora do archlinux, instalei o pacman no termux e configurei tudo certinho mas o yay precisa da linguagem go 1.19 e o termux instala o go 1.12 e não tem o binário pronto em arm, então estou tentando compilar o go 1.19 para instalar o yay no termux.

  • @GotUpLateWithMoon
    @GotUpLateWithMoon 2 ปีที่แล้ว +1

    thank you!

  • @user-wc5uc3jb4n
    @user-wc5uc3jb4n 11 หลายเดือนก่อน +1

    What if I now would like to crosscompile a random other package like tensorflow?

    • @jensdbe
      @jensdbe  11 หลายเดือนก่อน

      Similar approach for that. Pre-compile any prerequisites by doing ./configure and make. Then do the same for the actual package/binary that you want to compile. As I did for tcpdump in the video.
      Usually a bit of reading is required for the specifics/flags for each tool.

  • @ourchannel9173
    @ourchannel9173 3 ปีที่แล้ว +1

    Need help with sp805 watchdog timer , pls can you share steps to program its drivers?

  • @mikolajwojnicki2169
    @mikolajwojnicki2169 3 ปีที่แล้ว +1

    I am not familiar with compiled languages. Could someone explain why in many cases (not shown in the video) programs don't work when compiled for a different architecture?
    In other words, why can't Apple just re-compile all it's programs so that they work on the M1 chip?

    • @jensdbe
      @jensdbe  3 ปีที่แล้ว

      This can get quite complex but, at least as far as I understand it, simply said this is because a lot of tools/programs contain code or instructions tailored to one architecture. This is mainly done to gain performance. By using architecture specific and optimized ways of addressing the hardware and resources you can gain speed. Most CPUs, even when in theory they are on the same architecture have this kind of optimizations. Before you can recompile such code for another architecture, you would need to replace that CPU/arch-specific code with an alternative that works on the new arch. And even if you can, there might be an impact in performance or you might hit other limitations.

    • @mikolajwojnicki2169
      @mikolajwojnicki2169 3 ปีที่แล้ว +1

      @@jensdbe Thanks for the reply!

    • @AbdennacerAyeb
      @AbdennacerAyeb 3 ปีที่แล้ว

      When you write a program you try to do your best to optimize it. So Apple old software are written in a such way that are optimized on that old arch. That's why it need to rewrite the program to optimize it with their new M1 chip instead of old PowerPC arch to intel x64 Adoption.

  • @SEX_ON_DRUGS
    @SEX_ON_DRUGS 3 ปีที่แล้ว +1

    v helpful video. thank u

    • @jensdbe
      @jensdbe  3 ปีที่แล้ว

      Thanks for the nice feedback :)

  • @vacagonzalo
    @vacagonzalo 2 ปีที่แล้ว +1

    thanks man!

  • @diegonayalazo
    @diegonayalazo 2 ปีที่แล้ว +1

    Thanks

  • @rrkw7974
    @rrkw7974 6 วันที่ผ่านมา

    can you please make videos for android cross compilation and load the lkm from your host machine to target

  •  2 ปีที่แล้ว

    strace last version doesn't give executable or any file even the compilation doesn't give any error.

    •  2 ปีที่แล้ว +1

      Fixed with --prefix=$HOME

  • @wojtekkryptowski7509
    @wojtekkryptowski7509 2 ปีที่แล้ว

    Is this can by apply on RasPi 4B on Ubuntu 20.4? I can't install programs because Rasp is aarch64 and programs on Ubuntu are for amd64. Is my assumption is correct?

    • @jensdbe
      @jensdbe  2 ปีที่แล้ว +1

      The easiest if off course to use tools and programs from the Ubuntu aarch64 repositories by using your regular package manager (apt). But if you need to compile something or want it static linked, then this is what you're looking for.

    • @wojtekkryptowski7509
      @wojtekkryptowski7509 2 ปีที่แล้ว

      @@jensdbe Thanks for info! Channel subscribe.

  • @darpanshrivastava3539
    @darpanshrivastava3539 2 ปีที่แล้ว

    Is there a way to cross-compile python script on, let's say Ubuntu, to run on raspberry Pi armv7l? I have been searching a way to do this but haven't been able to get a concrete solution.

    • @jensdbe
      @jensdbe  2 ปีที่แล้ว

      Python scrips are generally compiled at runtime so they are platform independent. You just need to have the same libraries installed and they should work

  • @KangJangkrik
    @KangJangkrik 2 ปีที่แล้ว

    I wish I could donate a better microphone to you

    • @jensdbe
      @jensdbe  2 ปีที่แล้ว +1

      In the meanwhile, I got myself a better microphone, check out my latest videos and hopefully you should see an improvement. Nevertheless, donations are always welcome :)

  • @yasminebenghozzi6538
    @yasminebenghozzi6538 3 ปีที่แล้ว

    Can you please make a tutorial how to cross compile a python script?

  • @spudhead169
    @spudhead169 9 หลายเดือนก่อน

    No, need to know how to compile a firmware image not an executable.