Raspberry pi arm linux gcc

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 skype one window

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.

Читайте также:  Sudo apt get install alt linux

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 

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Native Compiler: Installation Instructions

Toolchains Binaries Setup Guide

Clone this wiki locally

Raspberry Pi Toolchains Logo

Raspberry Pi GCC Native-Compiler ARM Toolchains Setup Guide

These ARM toolchains can be used directly on any Raspberry Pi 32-bit OSes for compiling programs for it.

  • Stretch: Used and generate code for Raspbian Stretch OS (Debian Version 9) and equivalent OS only.
  • Buster: Used and generate code for Raspbian Buster OS (Debian Version 10) and equivalent OS only.
  • Bullseye: Used and generate code for Raspbian Bullseye OS (Debian Version 11) and equivalent OS only.
  • These instructions are exclusively for GCC version 9.2.0 but will work with any compiler version available with this project.
  • These instructions are Linux-machines specific only.
sudo apt update && sudo apt dist-upgrade
sudo apt-get install build-essential gawk gcc g++ gfortran git texinfo bison wget bzip2 libncurses-dev libssl-dev openssl zlib1g-dev

Compressed pre-compiled GCC Toolchain binaries can be easily be downloaded from the project’s SourceForge Repository by clicking links given in the following table:

Читайте также:  Linux mint android usb

C. Extracting and Linking Binary

These Raspberry toolchains have the same standardized headers with no hardcoded paths, thereby can be directly used for an immediate application OR can be installed permanently for on a daily basis usage.

C1. Temporary Installation: Use these binaries directly (Recommended)

PATH=//bin:$PATH LD_LIBRARY_PATH=//lib:$LD_LIBRARY_PATH
wget https://raw.githubusercontent.com/abhiTronix/raspberry-pi-cross-compilers/master/utils/SSymlinker

Once it is downloaded, you just need to make it executable, and then run it for each path manually using the following commands:

sudo chmod +x SSymlinker ./SSymlinker -s /usr/include/arm-linux-gnueabihf/asm -d /usr/include ./SSymlinker -s /usr/include/arm-linux-gnueabihf/gnu -d /usr/include ./SSymlinker -s /usr/include/arm-linux-gnueabihf/bits -d /usr/include ./SSymlinker -s /usr/include/arm-linux-gnueabihf/sys -d /usr/include ./SSymlinker -s /usr/include/arm-linux-gnueabihf/openssl -d /usr/include ./SSymlinker -s /usr/lib/arm-linux-gnueabihf/crtn.o -d /usr/lib/crtn.o ./SSymlinker -s /usr/lib/arm-linux-gnueabihf/crt1.o -d /usr/lib/crt1.o ./SSymlinker -s /usr/lib/arm-linux-gnueabihf/crti.o -d /usr/lib/crti.o

C2. Permanent Installation:

 echo 'export PATH=/opt//bin:$PATH' >> .profile echo 'export LD_LIBRARY_PATH=/opt//lib:$LD_LIBRARY_PATH' >> .profile source .profile
 echo 'export PATH=/opt//bin:$PATH' >> .bashrc echo 'export LD_LIBRARY_PATH=/opt//lib:$LD_LIBRARY_PATH' >> .bashrc source .bashrc
 sudo ln -sf /usr/include/arm-linux-gnueabihf/asm/* /usr/include/asm sudo ln -sf /usr/include/arm-linux-gnueabihf/gnu/* /usr/include/gnu sudo ln -sf /usr/include/arm-linux-gnueabihf/bits/* /usr/include/bits sudo ln -sf /usr/include/arm-linux-gnueabihf/sys/* /usr/include/sys sudo ln -sf /usr/include/arm-linux-gnueabihf/openssl/* /usr/include/openssl sudo ln -sf /usr/lib/arm-linux-gnueabihf/crtn.o /usr/lib/crtn.o sudo ln -sf /usr/lib/arm-linux-gnueabihf/crt1.o /usr/lib/crt1.o sudo ln -sf /usr/lib/arm-linux-gnueabihf/crti.o /usr/lib/crti.o
  • Extra Step to use these binaries(temporarily) as your default native GCC Compiler(instead of default GCC 6.3.0 ) at the time of compilation:(For more info. refer #16, thanks @krcroft)
export AR="gcc-ar-9.2.0" export CC="gcc-9.2.0" export CXX="g++-9.2.0" export CPP="cpp-9.2.0" export FC="gfortran-9.2.0" export RANLIB="gcc-ranlib-9.2.0" export LD="$CXX"
GCCPATH="//libexec/gcc/arm-linux-gnueabihf/9.2.0" export ARFLAGS="--plugin $GCCPATH/liblto_plugin.so" export RANLIBFLAGS="--plugin $GCCPATH/liblto_plugin.so"

If these binaries helped you big time, please consider supporting it. Thank you.

Also, don’t forget to share your views & drop a ⭐

Источник

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