Raspi的交叉编译-执行程序以“分段错误"结束. [英] Cross Compiling for Raspi - Executing the programm ends in "Segmentation fault"
问题描述
我有一个自己编写的程序,我也想从我的x86机器上为Raspberry Pi构建程序.我正在使用eclipse生成的makefile,无法更改此内容.
I have a self-written programm which I want to build also for Raspberry Pi from my x86 machine. I'm using eclipse generated makefiles and cannot change this thing.
我已经阅读了raspi CC的本教程: Hackaday-Link .因为raspi也已经安装了gcc 4.9版本,所以我也尝试使用此版本的交叉编译器进行尝试.这个hello world程序也存在该问题:
I've read this tutorial for CC for raspi : Hackaday-Link. Because raspi also have installed gcc version 4.9, I also try it with this version of the cross compiler. The problem also exisits with this hello world programm:
#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,使其可执行并运行,即的输出.
是 Segmentation fault
.当执行 sudo ./hello_world
时,没有输出.
When compiling and running it directly on the raspi, the output is hello world!
. OK, thats fine.
But when cross-compiling it with version 4.9 of arm-linux-gnueabihf-g++-4.9
, then scp it to the raspi, make it executable and run it, the output of ./hello_world
is Segmentation fault
. When executing sudo ./hello_world
there is no output.
我试图获取有关文件的一些信息,并看到在raspi编译程序上本地输出:
I tried to get some information about the files and see that the locally on the raspi compiled program outputed:
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
谁能告诉我问题是什么以及如何解决?
Can anyone tell me what the problem is and how to solve it?
推荐答案
工具链编译器arm-linux-gnueabihf-gcc可以具有可以运行的不同默认参数:
Toolchain compiler arm-linux-gnueabihf-gcc can have different default parameters which one can get running:
arm-linux-gnueabihf-gcc -Q --help=target
在Raspberry Stretch上安装的编译器(我将只保留基本信息):
Compiler installed on Raspberry Stretch (I will leave essential information only):
<代码>-march = armv6-marm [启用]-mfloat-abi =硬-mfp16-format =无-mfpu = vfp
拉伸默认的交叉编译器:
Stretch default cross-compiler:
<代码>-march = armv7-a-marm [已禁用]-mfloat-abi =硬-mfp16-format =无-mfpu = vfpv3-d16
现在您看到了体系结构上的差异.因此,要使用交叉编译器,需要设置 march
来匹配您所需的CPU.还请注意,默认情况下,Debian交叉编译器会发出Thumb代码,而Raspberry Stretch会发出ARM代码
Now you see the difference in architecture. So to sompile with cross-compiler one will need to set march
to match your desired CPU.
Also note that Debian cross compiler by default emits Thumb code and Raspberry Stretch emits ARM code
我建议您在不支持设备的情况下交叉编译较新的CPU系列.
I suggest you're cross-compiling for newer CPU family while your device doesn't support it.
这篇关于Raspi的交叉编译-执行程序以“分段错误"结束.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!