Use gcc to compile different options to view the intermediate file generation

Overall Flow gcc compiler program C as shown below

Use the following command:

  1. .c---> .i
gcc -E hello.c
  1. .c--->.s
gcc -S hello.c
  1. .c--->.o
gcc -c hello.c
  1. .c--->.out
gcc hello.c
  1. .o disassemble
objdump -d hello.o

The following examples show you by a

First create a hello.c and a hello.h

Then use the first command gcc -E hello.c

The contents of the file preprocessing particularly large, only part of the screenshot.

And then view assembler files gcc -S hello.c

You can see, a .s file has been generated, there's a lot of content is very complex.

Then compiled object file gcc -c hello.c

Because the target file is a binary file, it can not be viewed by a text editor.

After linking an executable file gcc hello.c

You can also view by objdump disassembly tool disassembly objdump -d hello.o

Disassembled code to be more concise and readable than assembler code generated directly (eliminating a lot of redundant information)

Guess you like

Origin www.cnblogs.com/zhaijiayu/p/11404294.html