C/C ++ learning and learning
GCC
Everyone is familiar with gcc. It is a compiler with powerful functions. Its full name is: gun gcc.
Generally, it is called GCC, which has powerful functions and can compile many languages. Including c, c ++, java, ada, etc...
GCC Parameters
Gcc usually has many parameters. When I compile a small programgcc -o object source.cYou can.
But one time I wanted to check whether there were differences in execution efficiency between the two codes with the same purpose but different writing methods. So I checked the assembly code parameters during gcc compilation.
| Parameters |
Description |
| -C |
Only compile without link, generate*.oFile |
| -S |
Generate assembly code*.sFile |
| -E |
Pre-compile generation*.iFile |
| -G |
Debugging information is included in the executable program, which can be debugged by gdb. |
| -O |
Output the output file to the specified file. |
| -Static |
Link Static Link Library |
| -Library |
Link library |
Example
Easy to use:
gcc -E hello.c -o hello.i
In this way, we get a pre-compiled file.
There are some:
# 1 "main.cpp"# 1 "<built-in>" 1# 1 "<built-in>" 3# 175 "<built-in>" 3# 1 "<command line>" 1# 1 "<built-in>" 2# 1 "main.cpp" 2# 1 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream" 1 3# 37 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream" 3# 1 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config" 1 3# 16 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config" 3# 226 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config" 3typedef __char16_t char16_t;typedef __char32_t char32_t;# 349 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config" 3...
Something like this is to put some header files in it.
gcc -S hello.i -o hello.s
It is the assembly code. As follows:
.section __TEXT,__text,regular,pure_instructions .section __TEXT,__const .align 4LCPI0_0: .long 1127219200 ## 0x43300000 .long 1160773632 ## 0x45300000 .long 0 ## 0x0 .long 0 ## 0x0LCPI0_1: .quad 4841369599423283200 ## double 4.503600e+15 .quad 4985484787499139072 ## double 1.934281e+25 .section __TEXT,__text,regular,pure_instructions .globl _main .align 4, 0x90_main: ## @main .cfi_startproc## BB#0: pushq %rbpLtmp2: .cfi_def_cfa_offset 16Ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp...
Forgive me for being an idiot in assembly. I can only understand a little bit of assembly code, but it has been a long time for me to learn TT.
- Then compile and generate without Link
.oFile.
gcc -c hello.s -o hello.o
At this time, you cannot open it in a text editor. It is already a binary file. Both open and open0 1Now
After I opened it with sublime text 2, there were a bunch of hexadecimal code.
- Then generate the executable file:
gcc hello.o -o hello
At this time, the link is successfully compiled into an executable file.
Only used for execution./helloYou can.