gcc 交叉编译错误 line 1: syntax error: word unexpected (expecting ")")

来源:互联网 发布:微信随机红包算法 编辑:程序博客网 时间:2024/05/22 10:48

在交叉编译过程中,比如arm平台

 arm-linux-gcc -c hello -o hello

编译出来的程序在arm平台上运行时,将导致line 1: syntax error: word unexpected (expecting ")")错误,

这是由于 在编译目标hello的时候 使用了选项-c ,导致生成的hello 不是可执行文件,

可通过file hello 来查看其属性,如下所示:

hello: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped

从file命令可以看出目标文件hello并非可执行文件,执行时当然会报错。

正常情况下,编译hello目标,不应该使用-c 选项,得到的目标属性如下所示:

hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

编译出来的目标hello 可正常运行。