Arm linux gnueabihf bin ld

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

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

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

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?

Читайте также:  Linux узнать характеристики системы

I tried some different paths for —sysroot, but that did not help. I’m not really sure what path I should specify for the sysroot. See above regarding the directory structure of the toolchain. Also, some Googling seems to indicate that —sysroot does not help for libstdc++.

I would try either /gcc-linearo-arm-linux-gnueabihf-raspbian or /gcc-linearo-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf

go here launchpad.net/gcc-arm-embedded and download the tarball and extract. Set your path to the bin dir. done. Or go to codesourcery.com (now mentor graphics) get the lite version, untar/bz, set your path to the bin dir. done.

9 Answers 9

I’m gonna try to write this as a tutorial for you so it becomes easy to follow.

NOTE: This tutorial only works for older raspbian images. For the newer Raspbian based on Debian Buster see the following how-to in this thread: https://stackoverflow.com/a/58559140/869402

Pre-requirements

Before you start you need to make sure the following is installed:

apt-get install git rsync cmake libc6-i386 lib32z1 lib32stdc++6 

Let’s cross compile a Pie!

Start with making a folder in your home directory called raspberrypi .

Go in to this folder and pull down the ENTIRE tools folder you mentioned above:

git clone git://github.com/raspberrypi/tools.git 

You wanted to use the following of the 3 ones, gcc-linaro-arm-linux-gnueabihf-raspbian , if I did not read wrong.

Go into your home directory and add:

export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin 

to the end of the file named ~/.bashrc

Now you can either log out and log back in (i.e. restart your terminal session), or run . ~/.bashrc in your terminal to pick up the PATH addition in your current terminal session.

Now, verify that you can access the compiler arm-linux-gnueabihf-gcc -v . You should get something like this:

Using built-in specs. COLLECT_GCC=arm-linux-gnueabihf-gcc COLLECT_LTO_WRAPPER=/home/tudhalyas/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.7.2/lto-wrapper Target: arm-linux-gnueabihf Configured with: /cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.b uild/src/gcc-linaro-4.7-2012.08/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc- linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oort61/crosstool-ng/builds/arm-l inux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oort61/crosstool-ng/builds/ arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fo rtran --disable-multilib --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float= hard --with-pkgversion='crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08' --with-bugurl= https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgom p --enable-libssp --with-gmp=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-rasp bian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oort61/crosstool- ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc =/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux- gnueabihf/build/static --with-ppl=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf -raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oort61/cros stool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --wi th-libelf=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/a rm-linux-gnueabihf/build/static --with-host-libstdcxx='-L/cbuild/slaves/oort61/crosstool-ng/bui lds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static/lib -lpwl' --ena ble-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gol d --with-local-prefix=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-li nux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long Thread model: posix gcc version 4.7.2 20120731 (prerelease) (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08 ) 

But hey! I did that and the libs still don’t work!

We’re not done yet! So far, we’ve only done the basics.

Читайте также:  Linux is distributed under which license

In your raspberrypi folder, make a folder called rootfs .

Now you need to copy the entire /lib and /usr directory to this newly created folder. I usually bring the rpi image up and copy it via rsync:

rsync -rl --delete-after --safe-links pi@192.168.1.PI:/ $HOME/raspberrypi/rootfs 

where 192.168.1.PI is replaced by the IP of your Raspberry Pi.

Now, we need to write a cmake config file. Open ~/home/raspberrypi/pi.cmake in your favorite editor and insert the following:

SET(CMAKE_SYSTEM_NAME Linux) SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER $ENV/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc) SET(CMAKE_CXX_COMPILER $ENV/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++) SET(CMAKE_FIND_ROOT_PATH $ENV/raspberrypi/rootfs) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 

Now you should be able to compile your cmake programs simply by adding this extra flag: -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake .

git clone https://github.com/jameskbride/cmake-hello-world.git cd cmake-hello-world mkdir build cd build cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake ../ make scp CMakeHelloWorld pi@192.168.1.PI:/home/pi/ ssh pi@192.168.1.PI ./CMakeHelloWorld 

Источник

arm-linux-gnueabihf-ld: unrecognized option ‘-Wl,—gc-sections’

I am cross-compiling Qt for raspberry Pi using this link and I am facing some issues. When doing sudo make I get the following:

~/rpi-xtools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld -Wl,--gc-sections -Wl,-O1 -fuse-ld=gold -o ../../../bin/moc .obj/moc.o .obj/preprocessor.o .obj/generator.o .obj/parser.o .obj/token.o .obj/main.o -L/home/ytan/rpi-xtools/delme/qtbase/lib -lQt5Bootstrap -lpthread /home/ytan/rpi-xtools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld: unrecognized option '-Wl,--gc-sections' 

I know that -Wl,—gc-sections is a command to arm-linux-gnueabihf-g++ and not arm-linux-gnueabihf-ld, but I don’t know which Makefile I should dive into to change arm-linux-gnueabihf-ld to arm-linux-gnueabihf-g++. I seek thee desperately, O’ mysterious dwellers of the web.

1 Answer 1

arm-linux-gnueabihf-ld: unrecognized option '-Wl,--gc-sections' 

You are invoking the linker directly. The linker gets —gc-sections , not -Wl,—gc-sections .

If you were linking through the compiler driver, then you would use -Wl,—gc-sections . That recipe would look something like arm-linux-gnueabihf-gcc . -o moc -Wl,—gc-sections .

Be sure your compile flags include -ffunction-sections and/or -fdata-sections .

I don’t know which Makefile I should dive into to change arm-linux-gnueabihf-ld to arm-linux-gnueabihf-g++.

Since the linker is being invoked directly, and if the project is setup correctly, then you should only need to:

 CPPFLAGS="-DNDEBUG -g2 -O3 . " \ CFLAGS=". -ffunction-sections -fdata-sections" \ CXXFLAGS=". -ffunction-sections -fdata-sections" \ LDFLAGS=". --gc-sections" \ ./configure

If you have some flexibility, then you should convert to linking through the compiler driver. It is what the Clang and GCC folks recommend, and it will make it easy to do things like test your program with sanitizers ( -fsanitize=address , -fsanitize=undefined , etc). The compiler will add the proper libraries for you. Otherwise, you will need to figure them out by yourself (non-trivial on some systems, like OS X).

Читайте также:  Linux как посмотреть uid

Источник

Cross compiling and sysroot

I’ve been following instructions to cross compile code for the Raspberry Pi but I need some clarification regarding the tool chain and sysroot. My setup is as follows:
Host: 4.15.0-76-generic x86_64
Target Pi: 4.19.93+ armv6l I created a directory and downloaded the toolchain as follows:

$ mkdir rpi-cross $ cd rpi-cross $ git clone https://github.com/raspberrypi/tools 
$ mkdir sysroot $ rsync -avz pi@raspberrypi_ip:/lib sysroot $ rsync -avz pi@raspberrypi_ip:/usr/include sysroot/usr $ rsync -avz pi@raspberrypi_ip:/usr/lib sysroot/usr 
$ wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py $ chmod +x sysroot-relativelinks.py $ ./sysroot-relativelinks.py sysroot 
export CROSS_COMPILE=/home/j/rpi-cross/tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- export SYSROOT=/home/j/rpi-cross/sysroot 
CC=$(CROSS_COMPILE)gcc hello-world : main.c $(CC) --sysroot=$(SYSROOT) -march=armv6 -mfpu=vfp -mfloat-abi=hard -o hello-world main.c 
In file included from main.c:1:0: /home/j/rpi-cross/sysroot/usr/include/stdio.h:27:36: fatal error: bits/libc-header-start.h: No such file or directory #include 
//#include int main (int argc, char ** argv) < // printf("Hello, world \r\n"); return 0; >
/home/j/rpi-cross/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory /home/j/rpi-cross/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/4.9.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory 

I then edited the makefile as follows, removing the sysroot option, and put the call to printf back into main.c.

CC=$(CROSS_COMPILE)gcc hello-world : main.c $(CC) -march=armv6 -mfpu=vfp -mfloat-abi=hard -o hello-world main.c 

At which point the build was succesful and after copying the application onto the target I was able to run it.

$ file hello-world hello-world: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.6.32, not stripped 

Further investigation reveals that there is a sysroot folder under /home/james/rpi-cross/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/ which I assume the toolchain uses by default. This brings me to the crux of the question; what is wrong with the sysroot that I created by copying files from my target device? Is the best approch to use the sysroot that comes as part of the toolchain?

Источник

Оцените статью
Adblock
detector