当前位置:网站首页>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
边栏推荐
- Some errors in configuring the environment
- Function and usage of function pointer
- 研究發現,跨境電商客服系統都有這五點功能!
- Detailed explanation of C language pointer
- NSIS search folder
- Apple script
- Use stm32cubemx tool to write the demo program of FreeRTOS
- Openxlsx field reading problem
- The global and Chinese market of lithographic labels 2022-2028: Research Report on technology, participants, trends, market size and share
- Apple modify system shortcut key
猜你喜欢

LED display equipment records of the opening ceremony of the Beijing Winter Olympics
![[untitled] record the visual shock of the Winter Olympics and the introduction of the display screen](/img/43/7f8becc09c5ce7fe401bed140608f3.jpg)
[untitled] record the visual shock of the Winter Olympics and the introduction of the display screen

C language uses arrays to realize the intersection, union, difference and complement of sets

How to migrate the device data accessed by the RTSP of the easycvr platform to easynvr?

UEFI development learning 5 - simple use of protocol

UEFI development learning 2 - running ovmf in QEMU

Record the opening ceremony of Beijing Winter Olympics with display equipment

Embedded AI intelligent technology liquid particle counter

Application of ultra pure water particle counter in electronic semiconductors

Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
随机推荐
Opendrive record
Count and sort the occurrence times of specific fields through SQL statements
The research found that the cross-border e-commerce customer service system has these five functions!
Build your own random wallpaper API for free
How to excavate and research ideas from the paper
数字孪生实际应用案例-风机篇
High end electronic chips help upgrade traditional oil particle monitoring
Some errors in configuring the environment
A simple method to prove 1/t Fourier transform
2021-10-28
Extended application of single chip microcomputer-06 independent key
如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
Screen record of the opening ceremony of the Beijing winter olympics 2
[idea] common shortcut keys
L'étude a révélé que le système de service à la clientèle du commerce électronique transfrontalier a ces cinq fonctions!
Apple script
Altium designer 19.1.18 - clear information generated by measuring distance
Extern keyword function
Altium Designer 19.1.18 - 清除测量距离产生的信息
Pointnet++ classification practice