问题描述
我有带有 gcc 4.8.2 的 Ubuntu 12.01,并为运行旧的 2.6.23 内核的 Vortex86DX CPU 进行了交叉编译.
I have Ubuntu 12.01 with gcc 4.8.2 and did a cross compilation for the Vortex86DX CPU running an old 2.6.23 kernel.
我正在尝试以下测试代码:
I´m trying the following testing code:
#include <iostream>
int main()
{
std::cout << "Hello world" << std::endl;
}
使用以下命令行编译:
g++ -march=i586 test.cpp -o test586 -static -static-libgcc -static-libstdc++
当我在目标架构上运行 test586 时,我收到此错误:
When I run the test586 on the target architecture I´m getting this error:
$ ./test586
Illegal instruction
好吧,正如此处所指出的那样我需要为给定的架构构建整个工具链,但我真的很困惑如何去做:
Well, as pointed out here it seens that I need to build the whole toolchain for the given architecture, but I´m really confused about how to do it:
A) 因为我目前使用的是 Ubuntu 12.01,它是为 i686 架构构建的.我应该在这个 Ubuntu 中构建新的工具链吗?我是否应该使用较旧的 Ubuntu 构建一个 VM 并编译它(这对我来说是个问题,因为我需要 C++00x -C11 支持,而像 10.X gcc 这样的 Ubuntu 不支持它).
A) As I´m currently using Ubuntu 12.01, it is built for i686 architecture. Shall I build the new toolchain in this Ubuntu ? Shall I build a VM with an older Ubuntu and compile that (this is a problem for me as I need C++00x -C11 support, and Ubuntu like 10.X gcc does not support it).
b) 我无法构建目标硬件,因为它的内存和磁盘(256Mb RAM)非常少,而且是非常旧的 Linux 内核 2.6.23.
b) I cannot build in the target hardware, as it has very little memory and disk (256Mb RAM) and a very old Linux Kernel 2.6.23.
我对如何解决这个问题感到非常困惑,非常感谢您的帮助.这里
I´m really very confused on how to solve that and help is appreciated. here
推荐答案
这是因为你的 libstdc++ 链接为 i686 版本,与 vortex 平台不兼容.当您切换到动态链接(默认启用)时,您的示例将完美运行.
This is because your libstdc++ is linked as i686 version which is incompatible with vortex platform. When you switch to dynamic linkage (which is enabled by default) your example will work perfectly.
这篇关于Vortex86DX 关于 C++ 代码/工具链构建的非法指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!