Problems caused by executing the target file: syntax error: word unexpected

Source: Internet
Author: User

The problem caused by the execution of the target file: syntax error: word unexpected today 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. The difference between executing the target file on arm and pc is generally that the target file compiled by the gcc-c option is not executable, so this problem is not encountered, this is especially true for PCs. 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 1 ~ /Test $. /zh_display.o2-bash :. /zh_display.o: cannot execute binary fileARM. The error code returned when cross-Compilation of the target file is performed is 1 $. /hello_qt2. /hello_qt: line 1: syntax error: word unexpected (expecting ")") the prompt information on the PC can be understood at a glance, and the information 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 !! It is easy to distinguish between the target file and the executable file, 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 ~ /Test $ file hello_qt2hello_qt: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), not stripped3 4 ~ /Test $ file hello_qt.o5hello_qt.o: ELF 32-bit LSB relocatable, ARM, version 1, not stripped are both ELF files, but the target file is relocatable and the executable file is: executable. Readelf tool: View ELF file DETAILS 01 ~ /Test $ readelf-h hello_qt02ELF Header: 03 Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 0004 Class: ELF3205 Data: 2's complement, little endian06 Version: 1 (current) 07 OS/ABI: ARM08 ABI Version: 009 Type: EXEC (Executable file) 10 Machine: ARM11 Version: 0x112 Entry point address: 0x87f813 Start of program headers: 52 (bytes into file) 14 Start of section headers: 3948 (bytes into file) 15 Flag S: 0x202, has entry point, gnu eabi, software FP16 Size of this header: 52 (bytes) 17 Size of program headers: 32 (bytes) 18 Number of program headers: 619 Size of section headers: 40 (bytes) 20 Number of section headers: 2721 Section header string table index: 2422 23 ~ /Test $ readelf-h hello_qt.o24ELF Header: 25 Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 0026 Class: ELF3227 Data: 2's complement, little endian28 Version: 1 (current) 29 OS/ABI: ARM30 ABI Version: 031 Type: REL (Relocatable file) 32 Machine: ARM33 Version: 0x134 Entry point address: 0x035 Start of program headers: 0 (bytes into file) 36 Start of section headers: 1040 (bytes into file) 37 Flags: 0x200, gnu eabi, software FP38 Size of this header: 52 (bytes) 39 Size of program headers: 0 (bytes) 40 Number of program headers: 041 Size of section headers: 40 (bytes) 42 Number of section headers: 1643 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 two objects in the target file are: 1 Type: REL (Relocatable file) 2 Entry point address: 0x0, while the two objects in the Executable file are: 1 Type: EXEC (Executable file) 2 Entry point address: 0x87f8

Related Article

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.