树莓派的交叉编译
使用 RaspBerry Pi 和我的电脑,我试图交叉编译一个用 C++ 编写的简单 helloWorld.我正在使用适用于 linux 的 Code Sourcery 工具链进行编译.
With a RaspBerry Pi and from my computer, I'm trying to cross-compile a simple helloWorld written in C++. I'm using Code Sourcery toolchain for linux to compile.
当通过 TFTP 将 helloWorld 二进制文件复制到 raspBerry 并使用 chmod 授予它执行权限时,出现下一个错误:
When copy the helloWorld binary to raspBerry by TFTP and give it execution permissions with chmod, the next error appears:
非法指令"
如果在二进制文件上创建一个文件",我会得到:raspberry:ELF 32 位 LSB 可执行文件,ARM,版本 1 (SYSV),静态链接,剥离"
If make a 'file' over binary I get: "raspberry: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, stripped"
这是因为我在链接时使用了-static -static-libstdc++".
This is because I used "-static -static-libstdc++" when linking.
如果我不使用静态链接,错误是:分段错误"
If I don't use static linking, the error is: "Segmentation fault"
代码:
/*
* main.cpp
*
* Created on: 26/06/2012
* Author: ccortiz
*/
#include <iostream>
using namespace std;
int main(void){
cout << "Hello Cross Compilling for ARM!" << endl << flush;
return 0;
}
我怎样才能以正确的方式编译和运行我的程序?谢谢.
How could I compile and run my program in a right way? Thanks.
推荐答案
你得到 Segmentation fault
错误的原因是不同的 ABI.运行 Raspbian 时的 Raspberry Pi 使用 linux-arm-gnueabihf
ABI,它假定硬件支持 hardfp 和 VFP(这在 ARMv6 环境中很少见),因此需要一些额外的 GCC 和 EGLIBC 补丁(这些补丁可以是在 Raspbian 存储库中找到).
The reason why are you getting Segmentation fault
error is different ABI. Raspberry Pi when running Raspbian is using linux-arm-gnueabihf
ABI which assumes hardfp and VFP support in hardware (which is rare in ARMv6 environment) so requires some additional patches for GCC and EGLIBC (these patches can be found in Raspbian repository).
您的 Code Sourcery 跨工具链很可能没有这些补丁,因此它使用另一个 ABI (linux-arm-gnueabi
) 因此在运行时崩溃(静态链接有效,因为内核 ABI 没有取决于hardfp/softfp).
Your Code Sourcery cross-toolchain most likely does not have these patches, so it's using another ABI (linux-arm-gnueabi
) hence the crash at runtime (static linking works because kernel ABI does not depend on hardfp/softfp).
您可能收到 Illegal Instruction
错误的另一个可能原因是为 ARMv7 和 Raspberry Pi 配置的 Code Sourcery 交叉工具链是 ARMv6.但在这种情况下,静态和动态链接都会产生相同的错误.
Another possible reason why you may be getting Illegal Instruction
error is Code Sourcery cross-toolchain configured for ARMv7 and Raspberry Pi is ARMv6. But in this case both static and dynamic linking will yield the same error.
这是如何在 Windows 中构建 Raspberry Pi 交叉编译器的分步指南,hardfp/softfp ABI 版本.生成的交叉编译器支持 C++ 并且不依赖于 cygwin 运行时库 (cygwin1.dll).
Here is a step-by-step guide how to build Raspberry Pi cross compiler in Windows, both hardfp/softfp ABI versions. Resulting cross-compiler supports C++ and does not depend on cygwin runtime library (cygwin1.dll).
相关文章