【发布时间】:2016-08-17 16:57:07
【问题描述】:
我有一个自己编写的程序,我也想从我的 x86 机器上为 Raspberry Pi 构建它。我正在使用 eclipse 生成的 makefile 并且无法更改此内容。
我已经阅读了 raspi 的 CC 教程:Hackaday-Link。因为raspi也安装了gcc 4.9版本,我也用这个版本的交叉编译器试试。这个hello world程序也存在问题:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world!" << endl;
}
直接在raspi上编译运行时,输出为hello world!。没关系。
但是当与arm-linux-gnueabihf-g++-4.9的4.9版本交叉编译时,然后将其scp到raspi,使其可执行并运行它,./hello_world的输出是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
谁能告诉我问题是什么以及如何解决?
【问题讨论】:
-
你能把 ldd hello_world 的输出放上去吗
-
在你的 Pi 上,尝试 gdb hello_world,然后运行程序并观察它的段错误。然后使用 bt 获取回溯,它应该提供更多信息。
-
上raspi编译后的输出:
pi@raspberrypi:~ $ ldd hello_world /usr/lib/arm-linux-gnueabihf/libarmmem.so (0xb6f40000) libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6e52000) libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6dd7000) libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6daa000) libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c69000) /lib/ld-linux-armhf.so.3 (0x7f57c000) -
和交叉编译:
pi@raspberrypi:~ $ ldd hello_world_cc /usr/lib/arm-linux-gnueabihf/libarmmem.so (0xb6f1f000) libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6e31000) libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6e04000) libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6cc3000) libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6c48000) /lib/ld-linux-armhf.so.3 (0x7f587000) -
@FrancescaNannizzi gdb 的输出:
pi@raspberrypi:~ $ gdb hello_world_cc ... This GDB was configured as "arm-linux-gnueabihf". ... (gdb) run Starting program: /home/pi/hello_world_cc Program received signal SIGSEGV, Segmentation fault. 0x0005f7e2 in ?? () (gdb) bt #0 0x0005f7e2 in ?? () #1 0x0001062e in _start () (gdb)
标签: c++ linux compilation raspberry-pi cross-compiling