Summary of how GCC, objdump, and file commands are used under Linux

Source: Internet
Author: User

One, GCC compilers and common commands

The GCC compiler supports not only the C language, but also the ADA, C + +, and Objective-c languages. The general compilation process can be divided into four stages: preprocessing (preprocessing), compilation (compilation), assembly (Assembly), and connection (linking)

1, one step of the compilation instructions

Consists of four stages

GCC test.c–o Test

2. pretreatment

Inserts the contents of the header file into the test.c file, and-E is stopped after the end of the preprocessing and outputs the preprocessing results

Gcc–e Test.c–o test.i

3. Compiling

Compile to. i file, generate assembly code,-S indicates stop after generating assembly code,-O Output assembly code file

Gcc–s Test.i–o Test.s

4. Compilation

Compiling assembly code files into target files

Gcc–c Test.s–o TEST.O

5. Connection

Connect it to the C standard input and output library, and the resulting program test

GCC test.o–o Test

6. Implementation

In the command-line window, execute the./test

The meaning of different file representations:

TEST.C (source file)->test.i (-e preprocessed file)->test.s (-S assembly file)->TEST.O (-c destination file)->test (-o executable)

Compiling for multiple source files:

1, one step

GCC test1.c test2.c–o Test

2, some complex (the execution process and one step are the same, are pre-processing--------)

Gcc-c Test1.c-o TEST1.O
Gcc-c Test2.c-o TEST2.O
GCC test1.o test2.o-o Test

Meaning of common command options:

1,-c only compile not connected

2,-O optimized compiled code, followed by numbers to represent the optimization level

3,-o Specifies the file name of the output

4,-v shows the commands used at each step of the compilation process

Second, the use of the Objdump command

Objdump is a command to disassemble the target file or executable file under Linux

1, Objdump–d test

Those sections in the Undo table test that need to execute instructions

2, Objdump–h test

Show section header information for test

3, Objdump–s TEST.O

Output c source code and disassembly of the instruction control format

4, Objdump–h

Displays header summary information for each section of the target file

5, Objdump–r

Display the relocation entry for a file

6, objdump–t display file symbol table entrance

Third, File command

The file command is a command that detects the types of files and can read the encoding system of the file and some other information

Summary of how GCC, objdump, and file commands are used under Linux

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.