melreik
Posts: 1
Joined: Fri Nov 01, 2019 1:01 pm

How to install the Raspberry Pi cross compiler on my Linux host machine?

Fri Nov 01, 2019 1:04 pm

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 MyColes
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:

Code: Select all

Code: Select all

/gcc-linearo-arm-linux-gnueabihf-raspbian
    /arm-linux-gnueabihf
        /bin
            (contains g++, gcc, etc)
        /lib
            (contains libstdc++ library)
    /bin
        (contains arm-linux-gnueabihf-g++, arm-linux-gnueabihf-...)
    /lib
        (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.

~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/
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.

~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin$
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:

Code: Select all

Code: Select all

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?
Last edited by melreik on Sun Nov 03, 2019 2:34 am, edited 1 time in total.

timrowledge
Posts: 1290
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: How to install the Raspberry Pi cross compiler on my Linux host machine?

Fri Nov 01, 2019 7:14 pm

My first question is why you feel a need to do this. A Pi is perfectly capable of doing its own compiling for pretty much any project. About the only case I’ve read of which might justify a cross-compiler is building your own kernels.
Take the simple route and compile locally unless you really, really, have to do something else.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Kendek
Posts: 128
Joined: Thu Jul 25, 2019 4:39 pm
Location: Kaposvár, Hungary

Re: How to install the Raspberry Pi cross compiler on my Linux host machine?

Fri Nov 01, 2019 8:10 pm

Just install the compiler from the Ubuntu repo:

Code: Select all

sudo apt install gcc-arm-linux-gnueabihf
or

Code: Select all

sudo apt install gcc-aarch64-linux-gnu
There is no need to use any other tool.

Return to “General discussion”