执行目标文件引发的问题:syntax error: word unexpected (expe...
今天不小心把一个目标文件当成了可执行文件放到开发板上进行执行,结果出现了这样一个问题:./hello_qt: line 1: syntax error: word unexpected (expecting ")"),因为以前没有碰到过这事,一时间有点蒙,就是一个简单的hello world按道理不会有问题才对。于是google了一下,原来是一个小小的-c编译选项搞得鬼。顺带也扩展学习总结了一下。
arm和pc上执行目标文件的区别
一般来说,gcc -c选项编译出来的目标文件是不可执行的,因此也就不会遇到这种问题,尤其是在PC上就更是如此。我这边是因为把文件转windows工作台,再通过tftp下载的开发板上,然后文件就全部是普通文件,都是自己chmod +x改的可执行,一时大意才难得碰上这问题。
- PC上执行目标文件的错误提示
1
2
|
~ /test $ . /zh_display .o - bash : . /zh_display .o: cannot execute binary file |
- ARM上执行交叉编译目标文件的错误提示
1
2
|
$ . /hello_qt . /hello_qt : line 1: syntax error: word unexpected (expecting ")" ) |
PC上的提示信息一看就懂,而ARM上的就会让人莫名奇妙了。一开始我怀疑是自己代码有问题,还反复检查了一遍,幸好只是一个简单的hello world程序,不然够我郁闷的。也多亏我及时google,否则还不知道要浪费多少时间在这小问题上,有时候google真的很重要呀!!
区分目标文件和可执行文件
目标文件和可执行文件平时都是很容易区分的,所以一般也不会注意这个。不过从今天的问题上,我又学到了不少关于两者差别的东西,还有区分两者的Linux工具。
- file工具:查看文件的基本属性信息
1
2
3
4
5
|
~ /test $ file hello_qt hello_qt: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), not stripped ~ /test $ file hello_qt.o hello_qt.o: ELF 32-bit LSB relocatable, ARM, version 1, not stripped |
两者均是ELF文件,但是目标文件是:relocatable, 而可执行文件是: executable。
- readelf工具:查看ELF文件的详细信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
~ /test $ readelf -h hello_qt ELF Header: Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS /ABI : ARM ABI Version: 0 Type: EXEC (Executable file ) Machine: ARM Version: 0x1 Entry point address: 0x87f8 Start of program headers: 52 (bytes into file ) Start of section headers: 3948 (bytes into file ) Flags: 0x202, has entry point, GNU EABI, software FP Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 6 Size of section headers: 40 (bytes) Number of section headers: 27 Section header string table index: 24 ~ /test $ readelf -h hello_qt.o ELF Header: Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS /ABI : ARM ABI Version: 0 Type: REL (Relocatable file ) Machine: ARM Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file ) Start of section headers: 1040 (bytes into file ) Flags: 0x200, GNU EABI, software FP Size of this header: 52 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 40 (bytes) Number of section headers: 16 Section header string table index: 13 |
-h选项读取ELF文件的文件头信息,注意其中的两项值:Type 和 Entry point address。Type信息就是file中的文件类型,而 Entry point address表示文件的执行入口点,只有可执行文件该项才有值,而目标文件是可重定向文件,还不可以直接执行,因此该项值为0.
目标文件两者为:
1
2
|
Type: REL (Relocatable file) Entry point address: 0x0 |
而可执行文件两者为:
1
2
|
Type: EXEC (Executable file) Entry point address: 0x87f8 |
执行目标文件引发的问题:syntax error: word unexpected (expe...的更多相关文章
- line: 1: Syntax error: word unexpected (expecting ")")
开发板上运行可执行程序报出错误: line1: 1: Syntax error: word unexpected (expecting ")") 解决思路: 1.编译器的问题 用a ...
- 可执行程序无法在Linux上运行,显示line 1: syntax error: word unexpected (expecting ") .
[问题]用arm-linux-gcc编译出来的可执行文件clkCtl,下载到板子上,在Linux下不能运行:./clkCtl: line 1: syntax error: word unexpecte ...
- line1: 1: Syntax error: word unexpected (expecting ")")
行时错误:line1: 1: Syntax error: word unexpected (expecting ")") 查看Makefile编译规则,可能由于依赖关系造成编译器使 ...
- 执行shell脚本报错:syntax error near unexpected token `或syntax error: unexpected end of file
引起此问题最可能的原因是: 在windows下编写的文件上传到linux执行. 我是在notepad++上编写的代码,之后上传到linux执行,报此错误.仔细检查,语法方面没有错误.上网查了一下,发现 ...
- 解决Linux下编译.sh文件报错 unexpected operator Syntax error: word unexpected
执行一个脚本 发现报语法错误,但是在其他机器上运行都没有问题 唯一的区别就是 一个是centos机器 报错的是ubuntu 网上搜索了一下 因为Ubuntu默认的sh是连接到dash的,又因为da ...
- 执行shell脚本提示“syntax error near unexpected token for((i=0;i<$length;i++))”
sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...
- linux后台执行./run.py提示python syntax error near unexpected token `('
python脚本中的#!/usr/bin/python 估计有不少人注意过一些python脚本开头有这么行东东: #!/usr/bin/python 它是用来干嘛的?貌似没有它对脚本功能也没啥 ...
- 解决执行脚本报syntax error: unexpected end of file或syntax error near unexpected token `fi'错误的问题
参考:https://blog.csdn.net/u012453843/article/details/69803244 解决执行脚本报syntax error: unexpected end of ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
随机推荐
- windows下本地安装oracle忘记密码,账号被锁咋办
忘记密码咋办: 进入cmd,输入set ORACLE_SID=ymxg (ORACLE_SID的值为你想登录的oracle实例的SID) 然后输入:sqlplus / as sysdba 最后输入: ...
- 0=='aa'的结果是true
来源于一道面试题: PHP的类型转换规则 1.如果是一个数字与一个字符串进行比较,那么会把字符串转换为数字再比较 2.字符串的转换规则,若字符串以数字开头,则取开头数字作为转换按结果,若无,则取0
- BNU 51638 Air Hockey 三分二分法
Air Hockey 无聊的过河船同学和无聊的胀鱼同学非常喜欢打桌上冰球(其实只是喜欢听球碰撞时的声音).在无聊的一天,无聊的过河船同学想到了一个无聊的玩法:两人同时将两个球放桌面上,同时击出,然 ...
- oc15--文档安装
// // main.m // 修改项目模板 /* 工程名称: 文件名称: 创建者 : 创建时间: 版权 : 修改人 : 修改时间: */ #import <Foundation/Foundat ...
- 读懂diff【转】
本文转载自:http://www.ruanyifeng.com/blog/2012/08/how_to_read_diff.html 读懂diff 作者: 阮一峰 日期: 2012年8月29日 d ...
- poj--3624--Charm Bracelet(动态规划 水题)
Home Problem Status Contest Add Contest Statistic LOGOUT playboy307 UPDATE POJ - 3624 Charm Bracelet ...
- Spring MVC简介 2.5 Spring MVC执行的流程
package org.fkit.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http ...
- 【优化算法】遗传算法GA求解混合流水车间调度问题(附C++代码)
00 前言 各位读者大家好,好久没有介绍算法的推文了,感觉愧对了读者们热爱学习的心灵.于是,今天我们带来了一个神奇的优化算法--遗传算法! 它的优点包括但不限于: 遗传算法对所求解的优化问题没有太多的 ...
- 使用autofac在mvc5下依赖注入
把遇到的问题汇总一下: 一.安装mvc5版本 命令:pm> Install-Package Autofac 结果安装的Autofac.Integration.Mvc(版本为4.0),所引用的依赖 ...
- 可以忽略的:BASH:/:这是一个目录
linux Ubuntu 14.04 在使用VIM编辑 /etc/profile 保存之后,出现了这个问题 其实,这个是可以忽略不计的问题,字符编码问题