Hello world代码中的Ilegal指令 [英] Ilegal instruction in Hello world code

查看:89
本文介绍了Hello world代码中的Ilegal指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是Linux编程的新手。我使用内核2.6.32在Centos 6主机中通过gcc编译器编译Hello world程序。使用的命令行是gcc -static hello.c -ohello。以前我在这台电脑上安装了GNUlibc(版本2.12)。

编译过程没问题,在主机(Pentium 4)上运行正常。当我使用AMD GEODE ​​LX800处理器和内核2.6.12将程序复制到嵌入式CPU时,运行结果为错误:非法指令



我检查了编译时gcc命令行中的不同参数:-mpc64,-m32,-march = i386,-march = geode,其中没有任何结果(编译正常,但运行错误非法指令)

I知道交叉编译是必要的,但不知道使用gcc的正确参数



代码就这么简单

main ()

{

printf(Hello world \ n);

}

Hi all,
I'm a newbie in Linux programming. I compile the "Hello world program" by means of gcc compiler in a Centos 6 host computer, with kernel 2.6.32. The command line used is gcc -static hello.c -ohello. Previously I have installed the GNUlibc (ver 2.12) in this computer.
The compile process is ok, and runs ok in the host computer (Pentium 4). When I copy the program to an embedded cpu with AMD GEODE LX800 processor and kernel 2.6.12, the running result is "error: illegal instruction"

I checked compile with different parameters in gcc command line: -mpc64, -m32, -march=i386, -march=geode with no results with any of them (compile is ok but running error "illegal instrucion")
I know a cross compiling is neccesary but don´t know the correct parameters to gcc to use

The code is as simple as this
main()
{
printf("Hello world\n");
}

推荐答案

这表明两个不同的系统针对CPU的不同指令集架构,并且CPU可能不同,或者可能是不同的情况: CPU是相同的,但在其中一个操作系统上,它可以在32位兼容模式下工作,并且不支持您编译的64位架构之一带领你的代码。请检查。



请参阅: http://en.wikipedia .org / wiki / Instruction_set [ ^ ]。



如果你需要一些更具体的细节,你必须弄清楚四个事实:什么是确切的CPU模型(如果你不知道它的指令集架构) ,操作系统版本的目标平台是什么,应该为这两个系统提供此信息。我想如果你得到这些信息,你就会很清楚自己出了什么问题。然后你可能需要为不同的平台交叉编译你的代码。



-SA
This is the indication of the fact that two different system are targeted to different instruction set architectures of the CPU, and the CPU could be different, or it could be different situation: the CPU are the same, but on one of the OS, it works in 32-bit compatibility mode and does not support one of the 64-bit architectures you compiled your code on. Please check up.

Please see: http://en.wikipedia.org/wiki/Instruction_set[^].

If you need some more concrete detail, you have to figure up to four facts: what is the exact CPU model (if you don't know it instruction set architecture), what is the target platform of the OS version, and this information should be provided for both systems. I think if you get this information, you well see by yourself what was wrong. And then you may need to cross-compile your code for different platform.

—SA


查看 http://en.wikipedia.org/wiki/Cross_compiler#GCC_and_cross_compilation [ ^ ]。也许这有助于为交叉编译设置环境。

干杯

Andi
Have a look at http://en.wikipedia.org/wiki/Cross_compiler#GCC_and_cross_compilation[^]. Maybe this helps in setting up the environment for cross compilation.
Cheers
Andi


这篇关于Hello world代码中的Ilegal指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆