illegal instruction错误

本文介绍了解决Qt4.6.3在FriendlyARM mini2440 Linux上编译过程中遇到的Illegal instruction错误的方法。通过使用特定版本的GCC编译器,并对Qt源码进行必要的配置修改,最终成功解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://www.kuche361.com/ht/view/id-39165

 

 

这是个臭名昭著的问题,试了很多方法,也没有解决。

7月15日~16日加起来搞了一天,把4.6.3重新编译了两次,还是没有解决,而且还证明用mini6410提供的4.5.1版本的gcc,能够编译成功,但是QT4.6.3下载到开发板运行Demo程序,提示错误,不兼容,郁闷啊,因此一定要用4.4.3版本的gcc。

其中,网上有一篇英文写的很好的文章,编译前修改了QT源码目录内两个.conf文件,尤其是后面红字部分特别提到了avoid some illegal instruction,以为可以类似解决:

Qt 4.6.2 installation procedure for FriendlyARM mini 2440 Linux

2011年03月21日 星期一 18:51

Qt 4.6.2 installation procedure for FriendlyARM mini 2440 Linux

Submitted by paolo on Sun 07/25/2010 - 03:44

This tutorial will provide a simple list of steps necessary to compile and install Qt 4.6.2 on Mini 2440 friendly ARM board. Italian speaking people can read this tutorial on Qt-Italia community website.

The board is equipped with the default GNU/Linux operating system (kernel 2.6.29)

This guide has been tested on following GNU/Linux host distributions:

CentOS 5.4

Fedora 12

Ubuntu 9.10

Some problems were found on following host distributions:

Ubuntu 9.04

OpenSUSE 11.2

First of all you have to download the GCC toolchain provided by the supplier:

Now untar the tgz file:

tar -xzf arm-linux-gcc-4.3.2.tgz

and then copy the directory tree under

/usr/local/

Remember to export this path on your shell

export PATH=/usr/local/arm/4.3.2/bin:$PATH

Now we can download Qt

and untar and unzip the file on a local directory (example: /home/user)

Now before running the configure tool you have to modify the qmake.conf file to inform Qt about your toolchain as described here:

File: mkspecs/qws/linux-arm-g++/qmake.conf

Now change following lines:

#QMAKE_CC = arm-linux-gcc

#QMAKE_CXX = arm-linux-g++

#QMAKE_LINK = arm-linux-g++

#QMAKE_LINK_SHLIB = arm-linux-g++

with:

QMAKE_CC = arm-none-linux-gnueabi-gcc

QMAKE_CXX = arm-none-linux-gnueabi-g++

QMAKE_LINK = arm-none-linux-gnueabi-g++

QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++

Also change the following lines:

#QMAKE_AR = arm-linux-ar cqs

#QMAKE_OBJCOPY = arm-linux-objcopy

#QMAKE_STRIP = arm-linux-strip

with:

QMAKE_AR = arm-none-linux-gnueabi-ar cqs

QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy

QMAKE_RANLIB = arm-none-linux-gnueabi–ranlib

In order toavoid some illegal instruction on your ARM compiled application binaries you have to deactivate compiler optimization:

File: /mkspecs/common/g++.conf

Change this line

QMAKE_CFLAGS_RELEASE += -O2

With:

QMAKE_CFLAGS_RELEASE += -O0

Now we are ready; in the Qt root subdirectory we run this command:

./configure -embedded arm -xplatform qws/linux-arm-g++ -prefix \

/usr/local/Qt -qt-mouse-tslib -little-endian -no-webkit -no-qt3support \

-no-cups -no-largefile -optimized-qmake -no-openssl -nomake tools

And then we can run the command

make

If everything is ok now we can do

make install

In order to run our ARM compiled applications we have to set following environment variables on the mini2440 board:

export TSLIB_TSEVENTTYPE=INPUT

export TSLIB_CONSOLEDEVICE=none

export TSLIB_FBDEVICE=/dev/fb0

export TSLIB_TSDEVICE=/usr/input/ts

export TSLIB_CALIBFILE=/usr/etc/pointercal

export TSLIB_CONFFILE=/usr/etc/ts.conf

export TSLIB_PLUGINDIR=/usr/lib/ts

export LD_LIBRARY_PATH=/usr/local/Qt/lib

export QTDIR=/usr/local/Qt

export QWS_MOUSE_PROTO=tslib:/usr/input/ts

export QWS_DISPLAY=LinuxFB:mmWidth=310:mmHeight=190

The Qt library binary (and fonts subdir) shall be placed on a user defined directory of the mini 2440m board and then it is necessary to set LD_LIBRARY_PATH to this directory.

Qt binary application must be run with –qws command line argument to inform Qt that we are working on a Linux embedded system.

Using the described procedure I was able to compile Qt qwt library and embedded widgets example.

YouTube Video demo: Embedded Widgets example

YouTube Video demo: Qwt examples

If you have questions you can leave a comment to this post or better you can post to this forum

Good Luck!

mini-2440-board

折腾半天,还是没有用,没有解决Illegal instruction错误问题。

### TC29X环境中的Illegal Instruction错误解决方案 非法指令(`illegal instruction`)通常表示程序试图执行处理器不支持的操作码。这可能是由于多种原因引起的,例如编译器优化设置不当、目标架构配置错误或硬件兼容性问题。 #### 可能的原因分析 1. **编译选项与目标架构不符** 如果使用的编译器未针对当前运行的目标架构正确配置,则可能导致生成的二进制文件包含无法被CPU识别的指令集[^3]。 2. **启用高级SIMD扩展** 当启用了某些特定于现代处理器的功能(如AVX、SSE或其他矢量指令),而实际运行环境缺乏这些功能时,也会触发此错误[^4]。 3. **库版本冲突** 使用了不同平台下构建的标准库或者第三方动态链接库也可能引发此类异常行为[^5]。 #### 解决方法建议 以下是几种常见的排查和修复策略: - #### 调整GCC/Clang编译参数 确保指定适合目标系统的微体系结构名称作为输入给 `-march=` 参数。例如,在较老一代Intel CPU上部署应用时可以尝试如下命令: ```bash gcc -O2 -march=corei7 -o program program.c ``` - #### 关闭不必要的向量化优化 对性能敏感度较低的应用场景来说,可以通过禁用自动向量化来规避潜在风险。具体做法是在Makefile或者其他构建脚本里加入下面这样的标志位: ```makefile CFLAGS += -fno-tree-vectorize ``` - #### 更新操作系统及其组件 验证是否存在已知漏洞影响到您的开发工具链,并及时安装官方发布的补丁包以消除安全隐患[^6]。 - #### 测试纯汇编部分代码逻辑 若项目中有嵌入式汇编码片段,则需特别留意其移植性和通用性;必要情况下改写成更跨平台友好的形式表达出来。 ```c __asm__("movl $1, %eax\n\t" "jmp *%ebx"); ``` 上述例子展示了如何通过内联方式调用手写的机器语言语句序列——但要注意这样做的局限性和可能带来的维护成本增加等问题。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值