当前位置:网站首页>Development tools -- gcc compiler usage
Development tools -- gcc compiler usage
2022-07-05 07:52:00 【Soy sauce;】
1.GCC compiler
GCC(GNU Compiler Collection, namely GNU Compiler package ), It's a set of GNU Developed programming Language compiler . It's a set of GPL And LGPL Free software released by license , It's also GNU The key part of the plan branch , It is also a kind of freedom Unix And Apple Computer Mac OS X Standard compiler for operating systems .GCC( Especially its Medium C Language compiler ) It's also often considered the de facto standard for cross platform compilers .
Linux Under the system GCC The compiler is actually GNU Compile a software in the tool chain , It can be used to call Other different tools such as pretreatment 、 compile 、 Compilation and linking such work .GCC Not only powerful , sex Can be superior , Its execution efficiency is higher than that of general compilers 20%~30%, And because it is GNU One of the project , It's open source software .
Often used in .c Generate exe Executable files are used
2.gcc Common options
gcc Common options :
-v: see gcc The version of the compiler , Show gcc Detailed process of execution
-o Place the output into (file It is also an executable )
notes : Specify the output file name as file, This name cannot have the same name as the source file name
-E Preprocess only; do not compile, assemble or link
Just preprocessing , I can't compile 、 assembly 、 link
-S Compile only; do not assemble or link
Compile only , I can't compile 、 link
-c Compile and assemble, but do not link
Compile and assemble , Will not link
//==================================================
gcc -v: see gcc The version of the compiler
3. Usage mode
The way 1:( Jump in one step )
gcc hello.c Output one a.out( Executable file ), then ./a.out To execute the application .
gcc -o hello hello.c Output hello, then ./hello To execute the application .
** The way 2:( Follow the compilation process to link )** The previous files are the results of their generation
gcc -E -o hello.i hello.c ( Preprocessing )
gcc -S -o hello.s hello.i ( compile )
gcc -c -o hello.o hello.s ( assembly )
gcc -o hello hello.o ( link )
notes :.o:object file(OBJ file )
explain : A code execution is divided into four steps
For details, see the interview classic 
Summary :
1) The input file's suffix and options are jointly determined gcc What are the operations to be performed .
2) During the compilation process , Unless you use -E、-S、-c Options ( Or a compilation error prevents the complete compilation process )
Otherwise, the last step is to link .
The way 3:
gcc -c -o hello.o hello.c( Direct use -C-O Preprocessing , compile , assembly )
gcc -o hello hello.o
gcc Would be right .c The file is preprocessed by default ,-c Let's go back to compilation 、 assembly , To get .o file
Re pass gcc -o hello hello.o take .o File links , Get the executable application .
The link is generated from the assembly OBJ file 、 System library OBJ file 、 Linking library files ,
Finally, the executable program that can run on a specific platform is generated .
crt1.o、crti.o、crtbegin.o、crtend.o、crtn.o yes gcc Join the system standard startup file ,
For general applications , These starts are required .
-lc: link libc The library files , among libc Library file printf Such as function .
gcc -v -nostdlib -o hello hello.o Will prompt because there is no link system standard startup file and standard library file , And the link failed .
This -nostdlib Options are often used on bare metal /bootloader、linux Kernel and other programs , Because they don't need startup files 、 Standard library files .
General applications only need system standard startup files and standard library files .
Bare pager /bootloader、linux Kernel and other programs do not need boot files 、 Standard library files .
Dynamic link uses dynamic link library to link , The generated program needs to load the required dynamic library to run during execution .
The program generated by dynamic link is smaller , But you have to rely on the dynamic libraries you need , Otherwise it can't be executed .
Static linking uses static libraries for linking , The generated program contains all the libraries needed to run the program , It can run directly ,
However, the program generated by static link is bulky .
gcc -c -o hello.o hello.c
gcc -o hello_shared hello.o
gcc -static -o hello_static hello.o
边栏推荐
- Altium designer 19.1.18 - clear information generated by measuring distance
- Random function usage notes
- The research found that the cross-border e-commerce customer service system has these five functions!
- RTOS in the development of STM32 single chip microcomputer
- 生产中影响滑环质量的因素
- Global and Chinese markets for anesthesia, breathing and sleep apnea devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of peeled bourdon tubes 2022-2028: Research Report on technology, participants, trends, market size and share
- MySQL - storage engine
- Pointnet++ classification practice
- Detailed explanation of C language pointer
猜你喜欢

Latex notes

研究發現,跨境電商客服系統都有這五點功能!

Win10 shortcut key

Altium Designer 19.1.18 - 导入板框

MySQL - storage engine

Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)

Opendrive arc drawing script

UEFI development learning 2 - running ovmf in QEMU

Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world

Ads usage skills
随机推荐
Batch modify the txt file code to UTF-8 (notepad++)
[professional literacy] specific direction of analog integrated circuits
Practical application cases of digital Twins - fans
NSIS finds out whether the file exists and sets the installation path
UEFI development learning 3 - create UEFI program
Openxlsx field reading problem
Day08 ternary operator extension operator character connector symbol priority
Explain STM32 startup file in detail
Day09 how to create packages import package naming conventions Alibaba Development Manual
Opendrive arc drawing script
Record the torch encountered by win10 cuda. is_ False problem in available()
Global and Chinese market of blackbody calibration source 2022-2028: Research Report on technology, participants, trends, market size and share
. Net service governance flow limiting middleware -fireflysoft RateLimit
A simple method to prove 1/t Fourier transform
Count and sort the occurrence times of specific fields through SQL statements
Distinction between heap and stack
Threads and processes
PIL's image tool image reduction and splicing.
Apple animation optimization
QT excellent articles