GCC 中树莓派的交叉编译.从哪儿开始? [英] Cross-compilation for Raspberry Pi in GCC. Where to start?

查看:43
本文介绍了GCC 中树莓派的交叉编译.从哪儿开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL/DR:我在哪里可以找到有关为 ARM (gnueabi) 平台(旨在在 Raspberry Pi 设备上运行)构建 GCC 4.7.0 交叉编译工具链的更多信息?p>

TL/DR: Where can I find more information about building a GCC 4.7.0 cross-compiling toolchain for ARM (gnueabi) platform (intended to run on a Raspberry Pi device)?

我刚得到一个全新的 Raspberry Pi,我非常渴望开始为它编程.我已经成功安装了 GCC 工具链(我使用的是 Arch Linux 系统映像)并编译了一些基本程序,一切正常.

I have just got a brand new Raspberry Pi and I am very eager to start programming for it. I've managed to install the GCC toolchain (I am using the Arch Linux system image) and compiled some basic programs, all working fine.

我也尝试编译 Boost 库,因为我经常在我的项目中使用它们,并且按照说明(./bootstrap.sh + ./b2),除了编译速度非常慢.我把它打开了几个小时,但它几乎没有超过最初的几个源文件.在我让它运行了一夜之后,我发现构建过程由于 RAM 不足而中止.

I've also tried to compile the Boost libraries because I often use them in my projects and everything seemed to work fine by following the instructions (./bootstrap.sh + ./b2) except for the fact that the compilation was painfully slow. I left it on for a few hours but it barely got past the first few source files. After I left it running for the night, I discovered that the build process aborted due to RAM shortage.

所以,我的猜测是 Rasp Pi 根本无法编译像 Boost 这样大小的东西.因此,我想到了交叉编译.然而,尽管网上有很多关于 ARM 交叉编译的信息,我还是觉得很混乱.甚至从哪里开始?

So, my guess is that Rasp Pi is simply underpowered for compiling something of such size as Boost. So, cross-compilation comes to my mind. However, even though there is a lot of information about ARM cross compilation available online, I find it confusing. Where does one even start?

我的 Raspberry Pi 上有一个最新的 GCC 版本 (4.7.0),所以我希望使用相同的版本进行交叉编译.我在哪里可以获得 ARM 的 GCC 4.7.0 工具链?(我将在 x86 CentOS 6.2 上编译)

I have a recent GCC version (4.7.0) available on my Raspberry Pi, so I would ideally like to cross-compile with the same version. Where can I get the GCC 4.7.0 toolchain for ARM? (I will be compiling on x86 CentOS 6.2)

我释放了不需要的 GPU 内存并在 USB 驱动器上设置了一个 4GB 交换分区,而构建文件位于 NFS 共享上.Boost 现在的编译速度要快得多,因此它是易于管理的.我仍然想知道如何在我的 x86 PC 上设置 GCC 4.7 工具链以进行交叉编译,因为我打算进行大量编译,并且希望它尽可能快.

I deallocated unneeded GPU memory and set up a 4GB swap partition on a USB drive, while build files are on a NFS share. Boost is now compiling much much faster, so it is manageable. I would still like to know how can I set up a GCC 4.7 toolchain for cross compilation on my x86 PC though, since I intend to do a lot of compiling and I would like it to be as fast as possible.

编辑 2:

由于 GCC 4.7.0 相对较新,似乎没有预构建的交叉编译器 (i386->ARM).我可能不得不自己建造一个,这似乎是一项不平凡的任务(我已经尝试过但失败了).有谁知道构建 GCC 交叉编译器的教程,希望是最新版本之一?

Since GCC 4.7.0 is relatively new, there does not seem to be a pre-built cross-compiler (i386->ARM). I will probably have to build one myself, which seems an non-trivial task (I've tried and failed). Does anyone know of a tutorial to follow for building a GCC cross-compiler, hopefully for one of the recent versions?

我已经尝试使用 这个很棒的 shell 脚本(它非常适合构建相同的-arch 编译器)并且我已经成功构建了 binutils 和 GCC 的先决条件,但是 GCC 构建一直失败并出现许多神秘错误.我真的迷路了,非常感谢您的帮助.

I've tried with this great shell script (which worked great for building a same-arch compiler) and I've successfully built binutils and GCC's prerequisites, but then GCC build kept failing with many cryptic errors. I am really lost here, so I would greatly appreciate your help.

Raspberry Pi 上的 GCC 配置为

GCC on Raspberry Pi was configured with

--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-bugurl=https://bugs.archlinux.org/ 
--enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-shared 
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit 
--disable-libunwind-exceptions --enable-clocale=gnu 
--disable-libstdcxx-pch --enable-libstdcxx-time 
--enable-gnu-unique-object --enable-linker-build-id --with-ppl 
--enable-cloog-backend=isl --enable-lto --enable-gold 
--enable-ld=default --enable-plugin --with-plugin-ld=ld.gold 
--with-linker-hash-style=gnu --disable-multilib --disable-libssp 
--disable-build-with-cxx --disable-build-poststage1-with-cxx 
--enable-checking=release --host=arm-unknown-linux-gnueabi 
--build=arm-unknown-linux-gnueabi 

编辑 3:

按照建议,我设法使用 this shell script 为 ARM 构建了一个 4.7 GCC 工具链(耶!)由用户 dwelch 在评论中.我还使用 这篇文章 构建了 newliblibstdc++作为向导.工具链工作正常,但是当我在 Raspberry Pi 上运行可执行文件时,它会因 Illegal instruction 而失败.这可能是什么原因?

I managed to build a 4.7 GCC toolchain for ARM (yay!) using this shell script as suggested by user dwelch in the comments. I also built newlib and libstdc++ using this article as a guide. The toolchain works fine, but hen I run the executable on my Raspberry Pi, it fails with Illegal instruction. What could be the cause of that?

推荐答案

我找到了这些说明 如何为您的 Raspberry Pi 构建交叉编译器.这是一个很好的使用 crosstool-ng 工具的教程,它简化了交叉编译器构建的配置 A LOT(它有一个很好的基于 curses 的界面)并且它支持 GCC 4.7.

I found these instructions How to build a cross compiler for your Raspberry Pi. It is a great walk through using a crosstool-ng tool which simplifies configuring a cross-compiler build A LOT (it has a nice curses-based interface) and it supports GCC 4.7.

看起来效果不错!

这篇关于GCC 中树莓派的交叉编译.从哪儿开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆