我有一个自己编写的程序,我想从我的 x86 机器上为 Raspberry Pi 构建它。我正在使用 eclipse 生成的 makefile,并且无法更改此内容。
我已经阅读了 CC for raspi 的教程:Hackaday 链接 http://hackaday.com/2016/02/03/code-craft-cross-compiling-for-the-raspberry-pi/。因为raspi也安装了gcc 4.9版本,所以我也用这个版本的交叉编译器尝试一下。这个 hello world 程序也存在这个问题:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world!" << endl;
}
直接在raspi上编译运行时,输出为hello world!
。好没关系。
但是当与 4.9 版本交叉编译时arm-linux-gnueabihf-g++-4.9
,然后将其 scp 到 raspi,使其可执行并运行它,输出./hello_world
is Segmentation fault
。执行时sudo ./hello_world
没有输出。
我尝试获取有关文件的一些信息,并看到本地 raspi 编译的程序输出:
pi@raspberrypi:~ $ file hello_world
hello_world: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=41161ae762d940b12c3313ca065a3badd284f6d3, not stripped
和交叉编译版本输出
pi@raspberrypi:~ $ file hello_world
hello_world: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=4f1f4fb86710ef8130f148dc5adae1c0c18092fd, not stripped
谁能告诉我问题是什么以及如何解决它?