当前位置:网站首页>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
边栏推荐
- Global and Chinese market for blood typing 2022-2028: Research Report on technology, participants, trends, market size and share
- Apple system shortcut key usage
- 1089 Insert or Merge 含测试点5
- MySQL - storage engine
- Function and usage of function pointer
- L'étude a révélé que le système de service à la clientèle du commerce électronique transfrontalier a ces cinq fonctions!
- msys2
- Significance and requirements of semiconductor particle control
- Altium Designer 19.1.18 - 导入板框
- 研究发现,跨境电商客服系统都有这五点功能!
猜你喜欢
Ads learning record (lna_atf54143)
Opendrive arc drawing script
研究发现,跨境电商客服系统都有这五点功能!
High end electronic chips help upgrade traditional oil particle monitoring
SQL JOINS
Altium designer 19.1.18 - Import frame
Numpy——1.數組的創建
生产中影响滑环质量的因素
UEFI development learning 5 - simple use of protocol
What is Bezier curve? How to draw third-order Bezier curve with canvas?
随机推荐
Using C language to realize IIC driver in STM32 development
[idea] common shortcut keys
Good websites need to be read carefully
Software designer: 03 database system
Global and Chinese markets for waste treatment air switches 2022-2028: Research Report on technology, participants, trends, market size and share
Batch modify the txt file code to UTF-8 (notepad++)
Global and Chinese markets for flexible endoscopic lithotripsy devices 2022-2028: Research Report on technology, participants, trends, market size and share
RTOS in the development of STM32 single chip microcomputer
NSIS finds out whether the file exists and sets the installation path
Global and Chinese market of rammers 2022-2028: Research Report on technology, participants, trends, market size and share
通过sql语句统计特定字段出现次数并排序
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
Screen record of the opening ceremony of the Beijing winter olympics 2
static的作用
Extended application of single chip microcomputer-06 independent key
IEEE access personal contribution experience record
软件设计师:03-数据库系统
Record the opening ceremony of Beijing Winter Olympics with display equipment
导电滑环磨损快的原因
Cadence learning records