简体   繁体   English

如何在我的 Linux 主机上安装树莓派交叉编译器?

[英]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.我正在尝试在我的 Ubuntu 机器上对 Raspberry Pi 进行交叉编译。

During my initial attempts I was using the arm-linux-gnueabi compiler, which is available in the Ubuntu repo.在我最初的尝试中,我使用了 Ubuntu 存储库中提供的 arm-linux-gnueabi 编译器。 I got this working.我得到了这个工作。 I was able to build all my dependencies and use the cross-compiler in my cmake project.我能够构建所有依赖项并在我的 cmake 项目中使用交叉编译器。

However, I believe I should be using the hf version, so I switched to arm-linux-gnueabihf.但是,我相信我应该使用 hf 版本,所以我切换到 arm-linux-gnueabihf。 Then I realized that this does not work with Raspberry Pi since it is armv6.然后我意识到这不适用于 Raspberry Pi,因为它是 armv6。

After some Googling, I then found the pre-built toolchain from GitHub .在谷歌搜索之后,我从 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.如果我将目录更改为 INNER bin 文件夹,则可以从终端编译测试程序而不会出现任何问题。

~/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.然后我尝试在 OUTER bin 文件夹中编译一个测试程序,其中包含工具的前缀版本。

 ~/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:但是,当我现在尝试使用编译器时(从内部 bin 目录之外),却找不到工具链附带的 libstdc++ 共享库:

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.此外,我希望能够使用编译器而不必导航到 bin 目录。 So I tried adding the OUTER bin directory (since I want the prefixed versions) and both lib directories to my PATH:所以我尝试将 OUTER bin 目录(因为我想要带前缀的版本)和两个 lib 目录添加到我的 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?我应该如何“安装”工具链,以便我可以从任何地方使用工具链,就像我使用 Ubuntu 存储库中的交叉编译器一样?

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.注意:本教程仅适用于较旧的 raspbian 映像。 For the newer Raspbian based on Debian Buster see the following how-to in this thread: https://stackoverflow.com/a/58559140/869402对于基于 Debian Buster 的较新 Raspbian,请参阅此线程中的以下操作方法: 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!让我们交叉编译一个 Pie!

Start with making a folder in your home directory called raspberrypi .首先在您的主目录中创建一个名为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.如果我没有读错,您想使用以下 3 个, gcc-linaro-arm-linux-gnueabihf-raspbian

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到名为~/.bashrc的文件的末尾

Now you can either log out and log back in (ie restart your terminal session), or run . ~/.bashrc现在您可以注销并重新登录(即重新启动终端会话),或者运行. ~/.bashrc . ~/.bashrc in your terminal to pick up the PATH addition in your current terminal session. . ~/.bashrc在您的终端中选择PATH在您当前的终端会话中添加。

Now, verify that you can access the compiler arm-linux-gnueabihf-gcc -v .现在,验证您是否可以访问编译器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.到目前为止,我们只完成了基础工作。

In your raspberrypi folder, make a folder called rootfs .在您的raspberrypi文件夹中,创建一个名为rootfs的文件夹。

Now you need to copy the entire /lib and /usr directory to this newly created folder.现在您需要将整个/lib/usr目录复制到这个新创建的文件夹中。 I usually bring the rpi image up and copy it via rsync:我通常将 rpi 图像调出并通过 rsync 复制它:

rsync -rl --delete-after --safe-links pi@192.168.1.PI:/{lib,usr} $HOME/raspberrypi/rootfs

where 192.168.1.PI is replaced by the IP of your Raspberry Pi.其中192.168.1.PI被 Raspberry Pi 的 IP 替换。

Now, we need to write a cmake config file.现在,我们需要编写一个cmake配置文件。 Open ~/home/raspberrypi/pi.cmake in your favorite editor and insert the following:在您喜欢的编辑器中打开~/home/raspberrypi/pi.cmake并插入以下内容:

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/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 .现在你应该能够通过添加这个额外的标志来编译你的cmake程序: -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake

Using a cmake hello world example:使用cmake hello world示例:

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

Building for newer Raspbian Debian Buster images and ARMv6为较新的 Raspbian Debian Buster 映像和 ARMv6 构建

The answer by @Stenyg only works for older Raspbian images. @Stenyg 的答案仅适用于较旧的 Raspbian 图像。 The recently released Raspbian based on Debian Buster requires an updated toolchain:最近发布的基于 Debian Buster 的 Raspbian 需要更新的工具链:

In Debian Buster the gcc compiler and glibc was updated to version 8.3.在 Debian Buster 中,gcc 编译器和 glibc 已更新到版本 8.3。 The toolchain in git://github.com/raspberrypi/tools.git is still based on the older gcc 6 version. git://github.com/raspberrypi/tools.git的工具链仍然基于较旧的 gcc 6 版本。 This means that using git://github.com/raspberrypi/tools.git will lead to many compile errors.这意味着使用git://github.com/raspberrypi/tools.git会导致很多编译错误。

This tutorial is based on @Stenyg answer.本教程基于@Stenyg 答案。 In addition to many other solutions in the internet, this tutorial also supports older Rasperry Pi (A, B, B+, Zero ) based on the ARMv6 CPU.除了互联网上的许多其他解决方案,本教程还支持基于 ARMv6 CPU 的较旧的 Rasperry Pi(A、B、B+、)。 See also: GCC 8 Cross Compiler outputs ARMv7 executable instead of ARMv6另请参阅: GCC 8 交叉编译器输出 ARMv7 可执行文件而不是 ARMv6

Set up the toolchain设置工具链

There is no official git repository containing an updated toolchain (See https://github.com/raspberrypi/tools/issues/102 ).没有包含更新工具链的官方 git 存储库(请参阅https://github.com/raspberrypi/tools/issues/102 )。

I created a new github repository which includes building and precompiled toolchains for ARMv6 based on GCC8 and newer:我创建了一个新的 github 存储库,其中包括基于 GCC8 和更新版本的 ARMv6 构建和预编译工具链:

https://github.com/Pro/raspi-toolchain https://github.com/Pro/raspi-toolchain

As mentioned in the project's readme, these are the steps to get the toolchain.正如项目的自述文件中提到的,这些是获取工具链的步骤。 You can also build it yourself (see the README for further details).您也可以自己构建它(有关更多详细信息,请参阅自述文件)。

  1. Download the toolchain:下载工具链:
wget https://github.com/Pro/raspi-toolchain/releases/latest/download/raspi-toolchain.tar.gz
  1. Extract it.提取它。 Note: The toolchain has to be in /opt/cross-pi-gcc since it's not location independent.注意:工具链必须在/opt/cross-pi-gcc因为它不是位置无关的。
sudo tar xfz raspi-toolchain.tar.gz --strip-components=1 -C /opt
  1. You are done!你完成了! The toolchain is now in /opt/cross-pi-gcc工具链现在位于/opt/cross-pi-gcc

  2. Optional, add the toolchain to your path, by adding:可选地,通过添加以下内容将工具链添加到您的路径中:

export PATH=$PATH:/opt/cross-pi-gcc/bin

to the end of the file named ~/.bashrc到名为~/.bashrc的文件的末尾

Now you can either log out and log back in (ie restart your terminal session), or run . ~/.bashrc现在您可以注销并重新登录(即重新启动终端会话),或者运行. ~/.bashrc . ~/.bashrc in your terminal to pick up the PATH addition in your current terminal session. . ~/.bashrc在您的终端中选择PATH在您当前的终端会话中添加。

Get the libraries from the Raspberry PI从 Raspberry PI 获取库

To cross-compile for your own Raspberry Pi, which may have some custom libraries installed, you need to get these libraries onto your host.要为您自己的 Raspberry Pi(可能安装了一些自定义库)进行交叉编译,您需要将这些库放到您的主机上。

Create a folder $HOME/raspberrypi .创建一个文件夹$HOME/raspberrypi In your raspberrypi folder, make a folder called rootfs .在您的raspberrypi文件夹中,创建一个名为rootfs的文件夹。

Now you need to copy the entire /lib and /usr directory to this newly created folder.现在您需要将整个/lib/usr目录复制到这个新创建的文件夹中。 I usually bring the rpi image up and copy it via rsync:我通常将 rpi 图像调出并通过 rsync 复制它:

rsync -vR --progress -rl --delete-after --safe-links pi@192.168.1.PI:/{lib,usr,opt/vc/lib} $HOME/raspberrypi/rootfs

where 192.168.1.PI is replaced by the IP of your Raspberry Pi.其中192.168.1.PI被 Raspberry Pi 的 IP 替换。

Use CMake to compile your project使用 CMake 编译您的项目

To tell CMake to take your own toolchain, you need to have a toolchain file which initializes the compiler settings.要告诉 CMake 使用您自己的工具链,您需要有一个工具链文件来初始化编译器设置。

Get this toolchain file from here: https://github.com/Pro/raspi-toolchain/blob/master/Toolchain-rpi.cmake从这里获取这个工具链文件: https : //github.com/Pro/raspi-toolchain/blob/master/Toolchain-rpi.cmake

Now you should be able to compile your cmake programs simply by adding this extra flag: -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake and setting the correct environment variables:现在你应该能够通过添加这个额外的标志来编译你的cmake程序: -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake并设置正确的环境变量:

export RASPBIAN_ROOTFS=$HOME/raspberry/rootfs
export PATH=/opt/cross-pi-gcc/bin:$PATH
export RASPBERRY_VERSION=1
cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/raspberry/Toolchain-rpi.cmake ..

An example hello world is shown here: https://github.com/Pro/raspi-toolchain/blob/master/build_hello_world.sh这里显示了一个示例 hello world: https : //github.com/Pro/raspi-toolchain/blob/master/build_hello_world.sh

我不能让编译器( x64版本)使用sysroot ,直到我说SET(CMAKE_SYSROOT $ENV{HOME}/raspberrypi/rootfs)pi.cmake

For Windows host, I want to highly recommend this tutorial: :对于 Windows 主机,我要强烈推荐这个教程::

  • Download and install the toolchain下载并安装工具链
  • Sync sysroot with your RPi include/lib directories将 sysroot 与您的 RPi 包含/lib 目录同步
  • Compile your code编译你的代码
  • Drag and drop the executable to your RPi using SmarTTY使用SmarTTY将可执行文件拖放到您的RPi
  • Run it!运行!

Nothing more, nothing less!不多也不少!

Prebuilt GNU Toolchains available for Raspberry, Beaglebone, Cubieboard, AVR (Atmel) and more可用于 Raspberry、Beaglebone、Cubieboard、AVR (Atmel) 等的预构建 GNU 工具链

You may use clang as well.您也可以使用clang It used to be faster than GCC, and now it is quite a stable thing.以前比GCC还快,现在已经是相当稳定的东西了。 It is much easier to build clang from sources ( you can really drink cup of coffee during build process ).从源代码构建clang要容易得多(在构建过程中你真的可以喝杯咖啡)。

In short:简而言之:

  1. Get clang binaries (sudo apt-get install clang).. or download and build ( read instructions here )获取 clang 二进制文件 (sudo apt-get install clang).. 或下载并构建(在此处阅读说明
  2. Mount your raspberry rootfs (it may be the real rootfs mounted via sshfs, or an image).挂载你的树莓派 rootfs(它可能是通过 sshfs 挂载的真正的 rootfs,或者是一个镜像)。
  3. Compile your code:编译你的代码:

     path/to/clang --target=arm-linux-gnueabihf --sysroot=/some/path/arm-linux-gnueabihf/sysroot my-happy-program.c -fuse-ld=lld

Optionally you may use legacy arm-linux-gnueabihf binutils.您可以选择使用旧版 arm-linux-gnueabihf binutils。 Then you may remove "-fuse-ld=lld" flag at the end.然后你可以在最后删除“-fuse-ld=lld”标志。

Below is my cmake toolchain file.下面是我的 cmake 工具链文件。

toolchain.cmake工具链.cmake

set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

# Custom toolchain-specific definitions for your project
set(PLATFORM_ARM "1")
set(PLATFORM_COMPILE_DEFS "COMPILE_GLES")

# There we go!
# Below, we specify toolchain itself!

set(TARGET_TRIPLE arm-linux-gnueabihf)

# Specify your target rootfs mount point on your compiler host machine
set(TARGET_ROOTFS /Volumes/rootfs-${TARGET_TRIPLE})

# Specify clang paths
set(LLVM_DIR /Users/stepan/projects/shared/toolchains/llvm-7.0.darwin-release-x86_64/install)
set(CLANG ${LLVM_DIR}/bin/clang)
set(CLANGXX ${LLVM_DIR}/bin/clang++)

# Specify compiler (which is clang)
set(CMAKE_C_COMPILER   ${CLANG})
set(CMAKE_CXX_COMPILER ${CLANGXX})

# Specify binutils

set (CMAKE_AR      "${LLVM_DIR}/bin/llvm-ar" CACHE FILEPATH "Archiver")
set (CMAKE_LINKER  "${LLVM_DIR}/bin/llvm-ld" CACHE FILEPATH "Linker")
set (CMAKE_NM      "${LLVM_DIR}/bin/llvm-nm" CACHE FILEPATH "NM")
set (CMAKE_OBJDUMP "${LLVM_DIR}/bin/llvm-objdump" CACHE FILEPATH "Objdump")
set (CMAKE_RANLIB  "${LLVM_DIR}/bin/llvm-ranlib" CACHE FILEPATH "ranlib")

# You may use legacy binutils though.
#set(BINUTILS /usr/local/Cellar/arm-linux-gnueabihf-binutils/2.31.1)
#set (CMAKE_AR      "${BINUTILS}/bin/${TARGET_TRIPLE}-ar" CACHE FILEPATH "Archiver")
#set (CMAKE_LINKER  "${BINUTILS}/bin/${TARGET_TRIPLE}-ld" CACHE FILEPATH "Linker")
#set (CMAKE_NM      "${BINUTILS}/bin/${TARGET_TRIPLE}-nm" CACHE FILEPATH "NM")
#set (CMAKE_OBJDUMP "${BINUTILS}/bin/${TARGET_TRIPLE}-objdump" CACHE FILEPATH "Objdump")
#set (CMAKE_RANLIB  "${BINUTILS}/bin/${TARGET_TRIPLE}-ranlib" CACHE FILEPATH "ranlib")

# Specify sysroot (almost same as rootfs)
set(CMAKE_SYSROOT ${TARGET_ROOTFS})
set(CMAKE_FIND_ROOT_PATH ${TARGET_ROOTFS})

# Specify lookup methods for cmake
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Sometimes you also need this:
# set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# Specify raspberry triple
set(CROSS_FLAGS "--target=${TARGET_TRIPLE}")

# Specify other raspberry related flags
set(RASP_FLAGS "-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS")

# Gather and distribute flags specified at prev steps.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CROSS_FLAGS} ${RASP_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CROSS_FLAGS} ${RASP_FLAGS}")

# Use clang linker. Why?
# Well, you may install custom arm-linux-gnueabihf binutils,
# but then, you also need to recompile clang, with customized triple;
# otherwise clang will try to use host 'ld' for linking,
# so... use clang linker.
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld)

I could not compile QT5 with any of the (fairly outdated) toolchains from git://github.com/raspberrypi/tools.git.我无法使用来自 git://github.com/raspberrypi/tools.git 的任何(相当过时的)工具链编译 QT5。 The configure script kept failing with an "could not determine architecture" error and with massive path problems for include directories.配置脚本因“无法确定体系结构”错误和包含目录的大量路径问题而不断失败。 What worked for me was using the Linaro toolchain对我有用的是使用 Linaro 工具链

http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/runtime-linaro-gcc4.9-2016.02-arm-linux-gnueabihf.tar.xz http://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/runtime-linaro-gcc4.9-2016.02-arm-linux-gnueabihf.tar.xz

in combination with结合

https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py

Failing to fix the symlinks of the sysroot leads to undefined symbol errors as described here: An error building Qt libraries for the raspberry pi This happened to me when I tried the fixQualifiedLibraryPaths script from tools.git.未能修复 sysroot 的符号链接会导致未定义的符号错误,如下所述: An error building Qt libraries for the raspberry pi当我从 tools.git 尝试 fixQualifiedLibraryPaths 脚本时发生了这种情况。 Everthing else is described in detail in http://wiki.qt.io/RaspberryPi2EGLFS .http://wiki.qt.io/RaspberryPi2EGLFS中详细描述了其他一切。 My configure settings were:我的配置设置是:

./configure -opengl es2 -device linux-rpi3-g++ -device-option CROSS_COMPILE=/usr/local/rasp/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /usr/local/rasp/sysroot -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /usr/local/qt5pi -hostprefix /usr/local/qt5pi ./configure -opengl es2 -device linux-rpi3-g++ -device-option CROSS_COMPILE=/usr/local/rasp/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf--sysroot /usr/local/rasp/sysroot -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /usr/local/qt5pi -hostprefix /usr/local/qt5pi

with /usr/local/rasp/sysroot being the path of my local Raspberry Pi 3 Raspbian (Jessie) system copy and /usr/local/qt5pi being the path of the cross compiled QT that also has to be copied to the device. /usr/local/rasp/sysroot 是我本地 Raspberry Pi 3 Raspbian (Jessie) 系统副本的路径,/usr/local/qt5pi 是交叉编译的 QT 的路径,也必须复制到设备。 Be aware that Jessie comes with GCC 4.9.2 when you choose your toolchain.请注意,当您选择工具链时,Jessie 随附 GCC 4.9.2。

The initial question has been posted quite some time ago and in the meantime Debian has made huge headway in the area of multiarch support.最初的问题已经发布很久了,与此同时 Debian 在多架构支持方面取得了巨大进展。

Multiarch is a great achievement for cross compilation! Multiarch 是交叉编译的一大成就!

In a nutshell the following steps are required to leverage multiarch for Raspbian Jessie cross compilation:简而言之,需要以下步骤来利用 multiarch 进行 Raspbian Jessie 交叉编译:

  • On your Ubuntu host install Debian Jessie amd64 within a chroot or a LXC container.在您的 Ubuntu 主机上,在 chroot 或 LXC 容器中安装 Debian Jessie amd64。
  • Enable the foreign architecture armhf.启用国外架构 armhf。
  • Install the cross compiler from the emdebian tools repository.从 emdebian 工具库安装交叉编译器。
  • Tweak the cross compiler (it would generate code for ARMv7-A by default) by writing a custom gcc specs file.通过编写自定义 gcc 规范文件来调整交叉编译器(默认情况下它会为 ARMv7-A 生成代码)。
  • Install armhf libraries (libstdc++ etc.) from the Raspbian repository.从 Raspbian 存储库安装 armhf 库(libstdc++ 等)。
  • Build your source code.构建您的源代码。

Since this is a lot of work I have automated the above setup.由于这是很多工作,我已经自动化了上述设置。 You can read about it here:你可以在这里读到它:

Cross Compiling for Raspbian Raspbian 的交叉编译

there is a CDP Studio IDE available that makes cross compile and deploy quite simple from both windows and linux and you can just check the raspberry toolchain checkbox during the installation.有一个 CDP Studio IDE 可用,它使从 windows 和 linux 的交叉编译和部署变得非常简单,您可以在安装过程中选中 raspberry 工具链复选框。 (PS. it has GPIO and I2C support so no code is needed to access those) (PS。它具有 GPIO 和 I2C 支持,因此无需代码即可访问它们)

The IDE demo of raspberry use is up here: https://youtu.be/4SVZ68sQz5U树莓派使用的 IDE 演示在这里: https : //youtu.be/4SVZ68sQz5U

and you can download the IDE here: https://cdpstudio.com/home-edition您可以在此处下载 IDE: https : //cdpstudio.com/home-edition

I have created an example repository which shows how to cross-compile for a Raspberry Pi 4 using CMake.我创建了一个示例存储库,它展示了如何使用 CMake 为 Raspberry Pi 4 进行交叉编译。 It also includes the installation of the toolchain and some special steps necessary when cloning the root filesystem.它还包括工具链的安装和克隆根文件系统时所需的一些特殊步骤。 It should in principle be possible to use it for older Pis as well, but the toolchain might be a different one: https://github.com/spacefisch/raspberrypi-crosscompiling原则上也可以将它用于较旧的 Pis,但工具链可能不同: https : //github.com/spacefisch/raspberrypi-crosscompiling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM