当前位置:网站首页>gcc/g++的使用
gcc/g++的使用
2022-07-29 06:45:00 【爱学代码的学生】
目录
1. 什么是gcc/g++?
gcc/g++是一种编译器,用来将C/C++语言转换成机器语言
2. gcc是如何完成转换?
格式:gcc [选项] 编译的文件 [选项] [目标文件]
如果直接进行gcc [编译文件] -o [目标文件],则会直接生成可执行文件
gcc将高级语言转换成机器语言分为四个步骤:
1. 预处理
预处理中主要包含了四个步骤
- 头文件的展开
- 宏替换
- 注释替换
- 条件编译
格式:gcc -E test.c -o test.i

我们可以看见预处理阶段完成了我们所说的所有步骤
2. 编译
编译的最主要功能将高级语言转换成汇编语言
格式:gcc -S test.i -o test.s

汇编语言比起高级语言更加简洁
3. 汇编
编译的最重要步骤是将汇编语言转换成二进制语言,也就是机器可识别代码
格式:gcc -c test.s -o test.o

4. 链接
在生成.o结尾的文件后就标识着编译成功,接着我们就需要进行链接
格式:gcc test.o -o test

这里我们需要涉及一个重要的知识点,那就是我们为什么要进行链接?
我们已经将我们的代码编译成功了,链接的作用又是什么呢?

我们可以发现我们所写的代码中,包含了printf函数,而print这个函数是我们所实现的吗?明显不是,那我们调用这个函数就需要完成这个函数的实现,又因为我们没有完成这个函数的实现,但是库中实现了这个函数,因此我们在进行链接的时候是链接的那些库,以供我们完成运行。
库分为静态库和动态库
静态库是指编译链接时,将所实现的函数代码全部加入进可执行文件中,因此生成的文件比较大,但是在运行中就不需要在链接库函数
动态库是指编译链接时,没有将所实现的函数代码加入在可执行文件中,而是在链接期间链接了所需的库,这样可以节省空间
在Linux中,默认链接的是动态库

而我们也可以主动链接静态库

我们发现当链接静态库时,内存大小几乎是链接动态库的100倍
边栏推荐
- Ethernet interface introduction
- 330. 按要求补齐数组
- Homebrew brew update 长时间没反应(或卡在 Updating Homebrew...)
- [Charles' daily problems] when you open Charles, you can't use nails
- 如何使用gs_expansion扩展节点
- 【C语言刷LeetCode】67. 二进制求和(E)
- Hj37 statistics of the total number of rabbits per month Fibonacci series
- Remote invocation of microservices
- SQL优化
- Nodejs安装教程
猜你喜欢

Unity free element special effect recommendation

Flink real time warehouse DWD layer (traffic domain) template code

数组的子集能否累加出K

Win11vmware turns on the virtual machine and restarts on the blue screen and the solution that cannot be started

Ethernet interface introduction

Kubernetes (五) ---------部署 Kubernetes Dashboard

【charles日常问题】开启charles,使用不了钉钉

彻底搞懂kubernetes调度框架与插件

MutationObserver文档学习

Vite3.0 has been released, can you still roll it (list of new features)
随机推荐
ETL为什么经常变成ELT甚至LET?
Problems encountered in vmware16 installing virtual machines
上采样之反卷积操作
Thoroughly understand kubernetes scheduling framework and plug-ins
Unity sends a post request to the golang server for parsing and returning
Use vscode to configure Mysql to realize connection, query, and other functions
VMware16创建虚拟机:无法创建新虚拟机,不具备执行此操作的权限
After three years of outsourcing, the salary of automatic testing after job hopping is twice that of the original. The secret is
Custom events
个人博客系统(附源码)
如何使用gs_expansion扩展节点
接口测试实战项目03:执行测试用例
Why does ETL often become ELT or even let?
基于C语言设计的学籍管理系统
解决CSDN因版权不明而无法发布博客的问题
npm install 时,卡住不动,五种解决方法
Win11 system error: code execution cannot continue because ierutil.dll cannot be found. Reinstalling the program may fix this problem
Remote invocation of microservices
1172. The plate stack has a sequence table + stack
Interface test actual project 03: execute test cases