当前位置:网站首页>Basic usage of GCC
Basic usage of GCC
2022-07-24 11:48:00 【Xiaoyuan Xiaoyuan eats dumplings】
Catalog
Two 、GCC、gcc、g++ The relationship between the three
3、 ... and 、gcc The build process
5、 ... and 、gcc Compilation options
One 、GCC
GCC(GNU Compiler Collection) namely GNU Compiler Suite , It belongs to a programming language compiler , Its original name was GCC(GNU C Compiler) namely GNU c Language compiler , Although the abbreviations are the same, the functions are very different .GCC The original intention is to GNU A compiler specially written by the operating system , The original GNU Is dedicated to compiling C Code , Now it has been extended to compile C、C++、Java、Objective-C A collection of compilers for many programming languages
Two 、GCC、gcc、g++ The relationship between the three
gcc(GNU C Compiler) yes GCC Medium c compiler , and g++(GNU C++ Compiler) yes GCC Medium c++ compiler .gcc and g++ Both can be compiled c and cpp file , But there are differences .gcc Compiling cpp The grammar is in accordance with c To compile, but cannot be linked to by default c++ The library of (gcc Default link c library ,g++ Default link c++ library ).g++ compile .c and .cpp All the documents are unified according to cpp Syntax rules to compile . So generally compile c use gcc, compile c++ use g++.
3、 ... and 、gcc The build process
use gcc compile *.c Files do not directly generate executable files , In the process, it also goes through pretreatment 、 Compile and assemble several processes

- In the pretreatment stage ,gcc The header file to be called will be included , Replace macro constants and macro code snippets
- In the compilation phase ,gcc Will check the normalization of the code 、 Whether there are grammar mistakes, etc , After checking to be correct ,gcc Will translate the document into .s Suffix assembly file
- In the assembly phase ,gcc Will be able to .s Suffix assembly file Translate into .o Suffix target file ( Binary files recognized by the machine )
- In the link phase ,gcc Will link the target file to the Library , Generate executable files
Four 、 file type
stay Linux In the system , There is no uniform suffix for executable files , The system distinguishes executable files from non executable files according to the attributes of files . and gcc The suffix is used to distinguish the category of the input file , Let's introduce gcc Some of the agreed rules followed
.c A file with a suffix ,C Language source code file ;
.a A file with a suffix , Is a library file composed of object files ;
.C,.cc or .cxx A file with a suffix , yes C++ Source code file ;
.h A file with a suffix , Is the header file included in the program ;
.i A file with a suffix , It's pretreated C Source code file ;
.m A file with a suffix , yes Objective-C Source code file ;
.o A file with a suffix , Is the compiled target file ;
.s A file with a suffix , Is the assembly language source code file ;
.S A file with a suffix , Is a precompiled assembly language source code file
5、 ... and 、gcc Compilation options
Options | effect |
E | Activate preprocessing ; The header file 、 Macro expansion (.i file ) |
S | Activate preprocessing 、 compile ; Generate assembly code (.s file ) |
c | Activate preprocessing 、 compile 、 assembly ; Generate target file (.o file ) |
nothing | Activate preprocessing 、 compile 、 assembly 、 link ; Generate executable files (.out file ) |
o | Generate goals |
Wall | Open compilation alarm ( all ) |
g | Embed debugging information , convenient gdb debugging |
llib | link lib library ( Here is lowercase L ) amount to C++ #pragma comment(lib, “xxx.lib”) |
Idir | increase include Catalog ( This is capital i ) Header file path |
LDir | increase lib Catalog ( Compiling static and dynamic libraries ) |
Suppose the source file name is test.c.
1. No option to compile Links
usage :gcc test.c
effect : take test.c Preprocessing 、 assembly 、 Compile and link to form an executable . The output file is not specified here , The default output is a.out.
2. Options -o
usage :gcc test.c -o test
effect : take test.c Preprocessing 、 assembly 、 Compile and link to form an executable test.-o Option is used to specify the file name of the output file .
3. Options -E
usage :gcc -E test.c -o test.i
effect : take test.c Preprocessing output test.i file .
4. Options -S
usage :gcc -S test.i
effect : Will preprocess the output file test.i Assemble into test.s file .
5. Options -c
usage :gcc -c test.s
effect : Will assemble the output file test.s Compile output test.o file .
6. No option link
usage :gcc test.o -o test
effect : The output file will be compiled test.o Link to final executable test.
7. Options -O
usage :gcc -O1 test.c -o test
effect : Use compile optimization level 1 compiler . The level of 1~3, The higher the level, the better the optimization effect , But the longer it takes to compile .
边栏推荐
- Hash - 202. Happy number
- Leetcode 257. all paths of binary tree
- 三、MFC消息映射机制实现原理
- [TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering
- Import the data in MariaDB into columnstore
- C # entry series (29) -- preprocessing commands
- Cgo+gsoap+onvif learning summary: 9. Go and C conduct socket communication and onvif protocol processing
- 哈希——202. 快乐数
- 哈希——242.有效的字母异位词
- C language programming code
猜你喜欢

PDF处理还收费?不可能!

HCIP MGRE实验 第三天

【C和指针第14章】预处理器
![Detailed OSPF configuration of layer 3 switch / router [Huawei ENSP experiment]](/img/a9/f080940ec7bf94ab83c922990efa62.png)
Detailed OSPF configuration of layer 3 switch / router [Huawei ENSP experiment]

Shengxin weekly issue 37

Two important laws about parallelism

4*4图片权重的收敛规则

视频回放 | 如何成为一名优秀的地学和生态学领域的国际期刊审稿人?

IT圈中的Bug的类型与历史

Use prometheus+grafana to monitor server performance in real time
随机推荐
L1-049 seat allocation of ladder race
[deserialization vulnerability-01] Introduction to serialization and deserialization
字符串——541. 反转字符串 II
Two important laws about parallelism
The difference between YPbPr and YCbCr
1184. Distance between bus stops: simple simulation problem
运算放大器 —— 快速复苏笔记[贰](应用篇)
IT圈中的Bug的类型与历史
Operational amplifier - Notes on rapid recovery [1] (parameters)
Stack Title: basic calculator II
运算放大器 —— 快速复苏笔记[壹](参数篇)
Repeated calls, messages, idempotent schemes, full collation
One week's wonderful content sharing (issue 13)
A*与JPS
Microservice - eruka
C language programming code
一周精彩内容分享(第13期)
JMeter while controller
【C和指针第14章】预处理器
Leetcode 257. all paths of binary tree