当前位置:网站首页>GCC简介
GCC简介
2022-06-28 10:51:00 【MoyangCitta】
查看版本 gcc/g++ -v/--version
gcc工作流程
- 预编译(源代码:.c .c++ .h):gcc -E main.c -o main.i
- 编译(预处理后源代码:.i):gcc -S main.i -o main.s
- 汇编(汇编代码:.s):gcc -c main.s -o main.o
- 链接(目标代码:.o,启动代码,库代码,其他目标代码):gcc main.o -o main
- 预编译:删除所有“#define”,并展开所有宏定义,同时处理所有条件预编译指令,然后处理“#include”预处理指令,将被包含的文件插入到该预编译指令的位置,删除所有注释,添加行号和文件名标识,编译编译器产生调试用的符号信息及编译时产生编译错误和警告时显示行号,最后保留“#pragma”编译器指令,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作。
- 编译阶段:词法分析、语法分析、语义分析,代码优化,汇总符号,生成汇编代码。
- 汇编阶段:将汇编指令翻译成二进制格式,生成各个 section,生成符号表。
- 链接阶段:合并各个 section,调整 section 的起始位移和段大小,合并符号表,进行符号解析,给符号分配虚拟地址,符号重定位。
gcc和g++区别
- 后缀为.c的,gcc把它当作是C程序,而g++当作是c++程序
- 后缀为.cpp的,两者都会认为是C++程序
- 编译阶段,g++会调用gcc,但是在链接阶段,因为需要C++的库,所以在这里需要用g++来完成链接。
- 对于“_cplusplus”宏,它标志着编译器会把代码按C还是C++语法来解释,因此,如果后缀为.c,并且采用gcc编译器,则该宏就是未定义的,否则,就是已定义。
gcc参数选项
| 编译选项 | 说明 |
| -o test test.c / test.c -o test | 将test.c编译成可执行文件test |
| -I directory | 指定include包含文件的搜索目录 |
| -g | 在编译时生成调试信息 |
| -D | 在编译时指定一个宏 |
| -w | 不生成任何警告信息 |
| -W | 生成所有警告信息 |
| -On | 优化选项,-O0表示没有优化,-O1为缺省值,-O3优化级别最高 |
| -l | 在程序编译的时候,指定使用的库 |
| -L | 指定编译的时候,搜索库的路径 |
| -fPIC/fpic | 生成与位置无关的代码 |
| -shared | 生成共享目标文件,通常用在建立共享库时 |
| -std | 指定C标准 |
边栏推荐
- mysql数据库概述以及安装过程
- Internet of things application case of wireless module transparent transmission technology
- Makefile简介
- Fabric. How to use js brush?
- [unity][ecs] learning notes (II)
- Katalon框架测试一个web页面操作实例代码
- Ribbon核心源码解析
- Several methods of using ABAP to operate Excel
- Debug debugging in katalon
- 【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
猜你喜欢

【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)

Katalon当中的debug调试

JS基础1-JS引入与运算符
![[Unity]EBUSY: resource busy or locked](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[Unity]EBUSY: resource busy or locked

Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"

Day 6 script and animation system

Remote connection of raspberry pie in VNC viewer mode without display

Threads and thread pools

ruoyi集成积木报表(nice)

Realize an air conditioner with compose to bring you cool in summer
随机推荐
File的io流与base64
Training and recognition of handwritten digits through the lenet-5 network built by pytorch
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
appliedzkp zkevm(9)中的Bytecode Proof
An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
Who knows if it is safe to open an account with CSC securities
Fastposter v2.8.4 release e-commerce poster generator
[leetcode daily question] [December 19, 2021] 997 Find the town judge
Katalon当中的output使用方法
Knowing the details of redis RDB, you can step on many holes less
Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
Metersphere uses JS to refresh the current page
sentinel
Six fusion positioning technologies in wireless communication application of Internet of things
JS基础1-JS引入与运算符
Realize an air conditioner with compose to bring you cool in summer
JS基础2
[QT] connect syntax reference implementation
Dataease installation upgrade
【实操】Appium Settings app is not running after 5000ms