栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在我的Linux主机上安装Raspberry Pi交叉编译器?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在我的Linux主机上安装Raspberry Pi交叉编译器?

我将尝试为您编写本教程,以使其易于理解。

前提条件

在开始之前,需要确保已安装以下组件:

apt-get install git rsync cmake ia32-libs

让我们交叉编译一个Pie!

首先在您的主目录中创建一个名为的文件夹

raspberrypi

进入该文件夹,然后下拉您上面提到的ENTIRE tools文件夹:

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

gcc-linaro-arm-linux-gnueabihf-raspbian
如果我没看错的话,您想使用3个中的以下一个。

进入您的主目录并添加:

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

到名为的文件的末尾

~/.bashrc

现在,您可以注销并重新登录(即重新启动终端会话),也可以

. ~/.bashrc
在终端中运行以
PATH
在当前终端会话中提取其他内容。

现在,确认您可以访问编译器

arm-linux-gnueabihf-gcc -v
。您应该得到这样的内容:

Using built-in specs.COLLECT_GCC=arm-linux-gnueabihf-gccCOLLECT_LTO_WRAPPER=/home/tudhalyas/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.7.2/lto-wrapperTarget: arm-linux-gnueabihfConfigured 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-longThread model: posixgcc version 4.7.2 20120731 (prerelease) (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08 )

但是,嘿!我这样做了,但库仍然不起作用!

我们还没有完成!到目前为止,我们仅完成了基础操作。

在您的

raspberrypi
文件夹中,建立一个名为的文件夹
rootfs

现在,您需要将整个复制

/lib
/usr
目录到这个新创建的文件夹。我通常会调出rpi图像并通过rsync复制它:

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

其中,

192.168.1.PI
由您的树莓派的IP取代。

现在,我们需要编写一个

cmake
配置文件。
~/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)

现在,您应该

cmake
只需添加以下额外标志即可编译程序
-DCMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake

使用cmake hello world示例:

git clone https://github.com/jameskbride/cmake-hello-world.git cd cmake-hello-worldmkdir buildcd buildcmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake ../makescp CMakeHelloWorld pi@192.168.1.PI:/home/pi/ssh pi@192.168.1.PI ./CMakeHelloWorld


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/370651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号