当前位置:网站首页>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
边栏推荐
- 如何进行导电滑环选型
- Extended application of single chip microcomputer-06 independent key
- Realization of binary relation of discrete mathematics with C language and its properties
- Opendrive arc drawing script
- How to realize audit trail in particle counter software
- 2021-10-28
- [idea] common shortcut keys
- [neo4j] common operations of neo4j cypher and py2neo
- 通过sql语句统计特定字段出现次数并排序
- Function and usage of function pointer
猜你喜欢

From then on, I understand convolutional neural network (CNN)

Altium Designer 19.1.18 - 导入板框

Oracle-触发器和程序包

软件设计师:03-数据库系统

Altium designer 19.1.18 - change the transparency of copper laying

Extended application of single chip microcomputer-06 independent key

Significance and requirements of semiconductor particle control

Win10 shortcut key

A complete set of indicators for the 10000 class clean room of electronic semiconductors

What is Bezier curve? How to draw third-order Bezier curve with canvas?
随机推荐
Baiwen 7-day smart home learning experience of Internet of things
Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
Nombre - 1. Création de tableaux
The sublime version that XP can run is 3114
MySQL - storage engine
Altium designer 19.1.18 - change the transparency of copper laying
A complete set of indicators for the 10000 class clean room of electronic semiconductors
软件设计师:03-数据库系统
[idea] common shortcut keys
Can't find real-time chat software? Recommend to you what e-commerce enterprises are using!
cygwin
Practical application cases of digital Twins - fans
Apple modify system shortcut key
Opendrive record
High end electronic chips help upgrade traditional oil particle monitoring
Threads and processes
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
Detailed explanation of pragma usage
Temperature sensor DS18B20 principle, with STM32 routine code
万字详解八大排序 必读(代码+动图演示)