Raspi 的交叉编译 - 执行程序以 "Segmentation fault" 结束
Cross Compiling for Raspi - Executing the programm ends in "Segmentation fault"
我有一个自己编写的程序,我想在我的x86机器上为树莓派构建它。我使用的是eclipse生成的makefiles,不能更改这个东西。
我已经阅读了这个CC for raspi的教程:hackday - 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
时没有输出
我试着得到一些关于文件的信息,看到在本地的树莓编译程序输出:
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
谁能告诉我问题是什么以及如何解决它? 工具链编译器arm-linux-gnueabihf-gcc可以使用不同的默认参数来运行:
arm-linux-gnueabihf-gcc -Q --help=target
编译器安装在Raspberry Stretch(我将只留下必要的信息):
-march= armv6
-marm [enabled]
-mfloat-abi= hard
-mfp16-format= none
-mfpu= vfp
拉伸默认交叉编译器:
-march= armv7-a
-marm [disabled]
-mfloat-abi= hard
-mfp16-format= none
-mfpu= vfpv3-d16
现在您看到了架构上的差异。因此,要使用交叉编译器进行编译,需要设置march
以匹配所需的CPU。还要注意Debian交叉编译器默认会发出Thumb代码,而Raspberry Stretch会发出ARM代码
我建议你交叉编译新的CPU系列,而你的设备不支持它。
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 给定一个整数数组,需要在Max_Heap上运行操作。得到错误"segmentation fault",有什么想法吗?(C++)
- 循环时无法进入:"Segmentation fault"
- OpenGL "Segmentation fault"错误
- 如何修复访问动态数组中结构中的字符串变量时"segmentation fault (core dumped)"错误
- 如何修复 C++ 中的'Segmentation fault'错误
- 创建一个简单的类及其变量和函数不断返回" segmentation fault (core dumped)"、C++
- 在 Mac OS 上遇到的"Segmentation fault: 11" [C++]
- 在 Linux 上实施英特尔 MKL 的 DFT 时"Segmentation fault"
- 尝试读取包含 ints 并存储在 int vector 中的文件,但我不断收到错误"Segmentation fault (core dumped)"
- 在非空 std::list 上使用 std::list.back<int>() 时"Segmentation Fault"
- 我正在尝试通过说话传递一些字符串,它会读取它们,但我得到了"segmentation fault"
- 为什么当我更改此代码时会给我"segmentation fault"错误?
- 尝试将文本文件加载到动态分配的 2D 数组中时出现'Segmentation fault'错误
- 将double打印到std::cout会导致Segmentation fault(C++)
- 将指针分配给链接列表节点会引发"Segmentation Fault"
- "Segmentation fault"使用 Cmake 在C++代码中运行 python 函数时
- 无法读取 Ubuntu "Segmentation fault (core dumped)"中的.dat或.bin文件
- 如何修复C++中的"Segmentation fault(core dump)"?