41

How do I set up GCC for cross compiling for the ARM processor? The host would be on x86_64 ( AMD64 - Ubuntu 12.04 ) and the target would be ARM (Raspberry Pi as well as Pandaboard - will do separate compilations for each)?

42

Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation.

You need to be careful on what flavour of linux and binutils you have on your target system. The newest stuff is hardfloat, in this case you would do:

sudo apt-get install gcc-arm-linux-gnueabihf

This brings in the complete cross-compile environment, including binutils.

  • On Ubuntu 13.10 you get gcc-4.7 for 'gnueabi' and gcc-4.8 for 'gnueabihf'. – nobar Feb 23 '14 at 23:34
  • when I tried to compile I got openssl/ossl_typ.h not found error though I already installed libssl-dev. – Necktwi Sep 10 '14 at 18:36
  • 1
    If you get source code from apt-get source, after apt-get build-dep you can normally just compile with dpkg-buildpackage -b -uc -us -r Is there a way to build a .deb this easily for ARM without changing the makefile? – Jonathan Dec 28 '14 at 4:39
  • @Maratyszcza could you please be more specific regarding the execution of line and then just use arm-linux-gnueabi-gcc instead of gcc for compilation? When I compile I use a call to make which, AFAIK, naturally points to /usr/lib/gcc or something close to that. How could I call arm-linux-gnueabi-gcc directly? – Momergil Nov 26 '15 at 17:01
  • 8
    @Momergil CC=arm-linux-gnueabihf-gcc make ... – Maratyszcza Nov 26 '15 at 19:05
1

The disk image provider must also provide a compatible cross compiler

This is the only reliable method.

For RPI in particular, the provided cross compilers are available at: https://github.com/raspberrypi/tools and can be used as explained at: https://raspberrypi.stackexchange.com/questions/64273/installing-raspberry-pi-cross-compiler/83215#83215

git clone https://github.com/raspberrypi/tools
export PATH="$(pwd)/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}"
printf '#include <stdio.h>\nint main() { puts("hello world"); }\n' > hello_world.c
printf '#include <iostream>\nint main() { std::cout << "hello world" << std::endl; }\n' > hello_world.cpp
arm-linux-gnueabihf-gcc -std=c99 -o hello_world_c hello_world.c
arm-linux-gnueabihf-g++ -std=c++11 -o hello_world_cpp hello_world.cpp

If you pick you own cross compiler wrongly, the following may happen:

My favorite alternative is to build your own image with Buildroot: https://stackoverflow.com/questions/47557262/how-to-download-the-torvalds-linux-kernel-master-recompile-it-and-boot-it-wi/49349237#49349237 This build everything from source and ensures that everything is compatible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.