I am attempting to get cross-compiling for Raspberry Pi working on my Ubuntu machine.

During my initial attempts I was using the arm-linux-gnueabi compiler, which is available in the Ubuntu repo. I got this working. I was able to build all my dependencies and use the cross-compiler in my cmake project.

However, I believe I should be using the hf version, so I switched to arm-linux-gnueabihf. Then I realized that this does not work with Raspberry Pi since it is armv6.

After some Googling, I then found the pre-built toolchain from GitHub: https://github.com/raspberrypi/tools.

I downloaded the toolchain, but I don't really understand how to "install" it. I extracted the files to my home directory. The directory structure looks like this:

            (contains g++, gcc, etc)
            (contains libstdc++ library)
        (contains arm-linux-gnueabihf-g++, arm-linux-gnueabihf-...)
        (gcc lib stuff)

If I change directory to the INNER bin folder I am able to compile a test program from the terminal without any problems.

arm-linux-gnueabihf/bin$ g++ test.cpp -o test

I then tried to compile a test program in the OUTER bin folder, which contains the prefixed versions of the tools.

 arm-linux-gnueabihf-g++ test.cpp -o test

However, when I try to use the compiler now (from outside the inner bin directory), it is unable to find the libstdc++ shared library that comes with the toolchain:

arm-linux-gnueabihf-gcc: error while loading shared libraries: 
libstdc++.so.6: cannot open shared object file: No such file or directory.

Furthermore, I want to be able to use the compiler without having to navigate to the bin directory. So I tried adding the OUTER bin directory (since I want the prefixed versions) and both lib directories to my PATH:

export PATH=$PATH:~/tools/.../bin
export PATH=$PATH:~/tools/.../lib
export PATH=$PATH:~/tools/.../.../lib

However, this results in the same error. How should I "install" the toolchain so that I can use the toolchain from everywhere, just like I can when I use the cross-compilers from the Ubuntu repo?

  • 1
    "arm-linux-gnueabi compiler, which is available in the Ubuntu repo" -> Most distro cross-compilers are ARMv7, so not compatible with Raspbian. "so I switched to arm-linux-gnueabihf. Then I realized that this does not work with Raspberry Pi since it is armv6" -> You haven't said which model or target OS you want. Raspbian is compiled for ARMv6, more specifically a variant with hardware float support. So there is a good chance that is the right one. – goldilocks Apr 2 '17 at 13:26
up vote 4 down vote accepted

The primary target of the Ubuntu arm-linux-gnueabi cross compiler is to compile for a different architecture of the same Ubuntu release leveraging the Debian/Ubuntu multiarch capabilities. Example: You compile on Ubuntu 16.04 amd64 for Ubuntu 16.04 armel.

If you would like to do a similar thing for Raspbian I suggest the following approach:

  • On your Ubuntu host install Debian Jessie amd64 within a chroot or a LXC container.
  • Enable the foreign architecture armhf.
  • Install the cross compiler from the emdebian tools repository.
  • Tweak the cross compiler (it would generate code for ARMv7-A by default) by writing a custom gcc specs file.
  • Install armhf libraries (libstdc++ etc.) from the Raspbian repository.
  • Build your source code.

Since this is a lot of work I have automated the above setup. You can read about it here: http://www.get-edi.io/Cross-Compiling-for-Raspbian/

I cannot reproduce the problem anymore

As of https://github.com/raspberrypi/tools/tree/5caa7046982f0539cf5380f94da04b31129ed521 it just works no matter which directory I'm on, just adding to PATH is enough:

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

Tested in Ubuntu 17.10.

The official documentation also documents that this should work: https://www.raspberrypi.org/documentation/linux/kernel/building.md (GitHub)

Related: https://stackoverflow.com/questions/19162072/how-to-install-the-raspberry-pi-cross-compiler-on-my-linux-host-machine

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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