The executable program cannot run on Linux. Line 1: syntax error: Word unexpected (expecting ")" is displayed.

Source: Internet
Author: User

Address: http://hi.baidu.com/serial_story/blog/item/450b060113846a067aec2cc2.html/cmtid/9e5675edc51727dbb21cb133

 

Related network posts: The e1750 module of Huawei 3G cannot be identified in my Android system, and the ttyusb * driver is not found in the/dev directory.

Http://topic.csdn.net/u/20111221/14/e9f55302-96bb-4243-b81c-b6d3c6eeab1c.html

 

 

[Fixed] the executable program cannot run on Linux. Line 1: syntax error: Word unexpected (expecting ") is displayed ")")

[Problem]
The executable clkctl compiled by arm-Linux-GCC is downloaded to the board and cannot be run in Linux:
./Clkctl: Line 1: syntax error: Word unexpected (expecting ")")

[Solution process]
1. This problem is also encountered on the Internet:
Syntax error: Word unexpected (expecting ")")
Http://hi.baidu.com/dsfire/blog/item/5d922458886ad589800a188b.html
It was uploaded to the Board via FTP, but the transmission was not complete, which caused a running problem,
But I use lrz to pass it through securecrt to ensure that the file is complete.

2. I thought I had a problem with the uimage and rootfs I burned and wrote it again,
Or not.

3. I thought there was a problem with the compiled file, so I switched to arm-Linux-uclibc-GCC to compile the file, and the result still failed. 4.

4.
An error occurred while running two test programs on a Linux-transplanted development board.
Http://linux.chinaunix.net/bbs/thread-1064286-1-1.html
So I went to the Linux server to check it. It seems to be OK as well:
File clkctl
Clkctl: Elf 32-bit LSB relocatable, arm, Version 1 (ARM), not stripped

I even used related tools to view the results. It seems to be OK:
Hexdump n 1 clkctl
Hexdump: N: no such file or directory
Hexdump: 1: no such file or directory
0000000 457f 464c 0101 6101 0000 0000 0000
0000010 0001 0028 0001 0000 0000 0000 0000
0000020 0630 0000 0000 0000 0034 0000 0000
...

Objdump-A clkctl

Clkctl: File Format elf32-little
Clkctl

Objdump-F clkctl

Clkctl: File Format elf32-little
Architecture: Unknown !, Flags 0x00000011:
Has_reloc, has_syms
Start address 0x00000000

Objdump-H clkctl

Clkctl: File Format elf32-little

Sections:
Idx name size vma lma file off algn
0. Text 000003e8 00000000 00000000 00000034 2 *** 2
Contents, alloc, load, reloc, readonly, code
1. Data 00000000 00000000 00000000 0000041c 2 ** 0
Contents, alloc, load, Data
2. BSS 00000004 00000000 00000000 0000041c 2 *** 2
Alloc
3. rodata 00000190 00000000 00000000 0000041c 2 *** 2
Contents, alloc, load, readonly, Data
4. Comment 00000012 00000000 00000000 000005ac 2 ** 0
Contents, readonly
5. Note. GNU-stack 00000000 00000000 00000000 000005be 2 ** 0
Contents, readonly
6. Arm. Attributes 00000010 00000000

5. I have posted n posts on Google, but I have not mentioned any specific problems,
There is only one post that seems to have come up with an idea:
After updating to air sdk 1.5.1 all flex air apps give "ABC bytecode decoding" error
Http://bugs.adobe.com/jira/browse/FBE-323
"
Flex_sdk_3/bin/adl_lin: 1: syntax error: Word unexpected (expecting ")")

I 've seen this error before and usually its a shell execution problem, but I'm not quite sure how to fix it here. Usually it's

Something like change #! /Bin/sh #! /Bin/bash, but since adl_lin is a binary file I'm not sure how to go about fixing it.

FYI: I'm running Ubuntu 8.04, if that is helpful in anyway.
"
It seems to be a sh problem,
However, I went to the/bin directory and looked at it. Sh seems to be okay.
# Sh -- Help
Busybox v1.13.2 (11:38:15 Cst) Multi-call binary

No help available.

It's really speechless .....

[Solution]
I just saw this post:
Cygwin and NMT toolchain
Http://www.networkedmediatank.com/showthread.php? Tid = 20303
I did not pay attention to it, but I did not intend to find it later. In the past, I explained the cause and introduced the solution...

The cause of all software errors can be found, which is no exception here.
The final result is that when I write a simple makefile and compile the command, I write it as follows:
$ (CC)-o $ (out_file)-C $ (src_file)
Instead, the-C option should be removed and directly compiled into an executable file:
$ (CC)-o $ (out_file) $ (src_file)

I have been confused about the-C parameter before, so I thought it was exactly the same as the C file...
Now it's wrong again...

The-C option of GCC indicates:
-C
Only activate preprocessing, compilation, and assembly, that is, he only makes the program into an OBJ file.
Example usage:
Gcc-C hello. c
It will generate the. o obj file

That is, if-C is not added, the executable file will be compiled by default.
Add-C to compile it into the target OBJ file, and do not compile it into an executable file...

Our actual commands
Arm-Linux-gcc-O clkctl-C clock_control.c
It means to compile clock_control.c into the target file. The output (target) file is called clkctl.
In fact, if-O clkctl is not written here, the default output file name is the same as the C file name, but the suffix is. O, which is clock_control.o.

Arm-Linux-gcc-O clkctl clock_control.c
It means that clock_control.c is compiled into an executable file (that is, the target file is first compiled and then linked to an executable file)
The output file name is clkctl. If-O clkctl is not added, the default output file name in Linux is a. Out,
It is easy to confuse and overwrite, and has no practical significance. Therefore, we generally add-O to specify the name of the executable program output.

In addition, there is another GCC parameter C in uppercase:
-C
During pre-processing, do not delete the annotation information, which is generally used with-E. Sometimes the analysis program is very convenient to use.
Be sure not to confuse it with the lower-case C...

[Appendix]
GCC Parameters
Http://man.lupaworld.com/content/develop/UNIX_system_develop_gcc.htm

[Summary]
Many other friends may have encountered the same problem as me,
The-C option is mistakenly added during compilation so that the generated file is not an executable file but a target file,
Therefore, it cannot be run during running.

I'm sorry, I forgot such basic knowledge ....

[Postscript]

In fact, it is still not enough of your own knowledge. I think of the information of the target file as the information of the executable file, because I used file to read the information of the real executable file, the result of viewing the target file is different from that of the previous file:

[Crifan @ localhost clock_control] $ file clock_control.o
Clock_control.o: Elf 32-bit LSBRelocatable, Arm, Version 1 (ARM), not stripped
[Crifan @ localhost clock_control] $ file clkctl
Clkctl: Elf 32-bit LSBExecutable, Arm, Version 1 (ARM), dynamically linked (uses SHARED libs), not stripped
[Crifan @ localhost clock_control] $

If you have the knowledge before, you can see the problem. Also, if your mind is flexible, you can use file to view other executable files and compare them with the above. The method is not correct...

Similarly, you can use the readelf tool to view the specific information:

[Crifan @ localhost clock_control] $
Readelf-H clkctl
Elf header:
Magic: 7f 45 4C 46 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: 0x854c
Start of program headers: 52 (bytes into file)
Start of section headers: 5036 (bytes into file)
Flags: 0x2, has entry point, GNU Eabi
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: 31
Section header string table index: 28
[Crifan @ localhost clock_control] $ ls
Clkctl clock_control.c clock_control.h clock_control.o clock-dev.ko makefile readme.txt
[Crifan @ localhost clock_control] $Readelf-H clock_control.o
Elf header:
Magic: 7f 45 4C 46 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: 1584 (bytes into file)
Flags: 0x0
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: 12
Section header string table index: 9

 

 

 

// ================================================ ======================================

Note:

1> today, I found that my application cannot be executed. Instead of calling the system command, it is not because of incorrect compilation versions, because the system's own application reports the same error under ADB.

2> simple applications (such as toolbox: ls + CD + cat) can be executed directly under ADB, but complex applications must be called using the system command before they can be correctly executed, for example, system ("mytest ")

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.