Problems caused by executing the target file: syntax error: Word unexpected (Expe...

Source: Internet
Author: User

Today, I accidentally put a target file as an executable file on the Development Board for execution. The result is a problem :. /hello_qt: Line 1: syntax error: Word unexpected (expecting ")"), because I have never encountered this before, and it is a bit confusing for a while, it's just a simple hello World. So Google, it turned out to be a little-C compilation option. This article also provides a summary of the extended learning model.

What is the difference between running the target file on arm and PC?

In general, the target file compiled by the GCC-C option is not executable, so this problem is not encountered, especially on the PC. This is because I transfer files to the Windows workbench, and then download them to the Development Board through TFTP. Then all the files are normal files, all of which can be modified by my own chmod + X, this problem is rare only when you are careless.

  • Error message for executing the target file on PC
?
12 ~/test$ ./zh_display.o-bash: ./zh_display.o: cannot execute binary file
  • Error message for executing cross-Compilation of target files on ARM
?
12 $ ./hello_qt./hello_qt: line 1: syntax error: word unexpected (expecting ")")

The prompt information on the PC can be understood at a glance, while those on the arm can be inexplicable. At first I suspected that I had a problem with my code and checked it again and again. Fortunately, it was just a simple hello World Program. Otherwise, it would be depressing to me. Thanks to Google in time, I still don't know how much time will be wasted on this small problem. Sometimes Google is really important !!

Differentiate between target and executable files

The target file and the executable file are easy to differentiate at ordinary times, so you generally do not pay attention to this. However, from today's issue, I have learned a lot about the differences between the two, as well as Linux tools that distinguish them.

  • File Tool: View the basic attributes of a file
?
12345 ~/test$ file hello_qthello_qt: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), not stripped ~/test$ file hello_qt.ohello_qt.o: ELF 32-bit LSB relocatable, ARM, version 1, not stripped

Both are Elf files, but the target files are:RelocatableWhile the executable file is:Executable.

  • Readelf Tool: View detailed information about the ELF File
?
12345678910111213141516171819202122232425262728293031323334353637383940414243 ~/test$ readelf -h hello_qtELF 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.oELF 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 option reads the file header information of the ELF File. Note the following two values: type and entry point address. The type information is the file type in the file, while the entry point Address indicates the execution entry point of the file. Only the item of the executable file has a value, and the target file is a redirected file, it cannot be executed directly, so the value of this item is 0.

The target files are:

?
12 Type:                              REL (Relocatable file)Entry point address:               0x0

The executable files are:

?
12 Type:                              EXEC (Executable file)Entry point address:               0x87f8

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.