gcc迁移手册

文章详细介绍了使用GCC编译C程序的步骤,包括预处理(-E),生成汇编文件(-S),编译汇编文件(-c),链接对象文件生成可执行文件,以及如何创建和使用静态库(-ar)和动态库(-shared)。同时提到了CMake等构建系统在管理多文件项目中的优势,以及如何使用-l和-L选项链接库,如数学库(-lm)和检查库是否存在(-ldconfig-p|greplua)。
摘要由CSDN通过智能技术生成

for more readable: see pre->asm->obj->exe

1. -E preprocess, gen a `.i` file, do not check syntax , for example: `gcc -E demo.c -o demo.i`

2. -S gen a `.s` file, for example:`gcc -S demo.i -o demo.s`

3. -c compile a `.s` file, for example: `gcc -c demo.s -o demo.o`, noticed that `.o` file is a binary file

4. to link all `.o` file and gen a target execuatble file, for example:`gcc a.o b.o c.o -o main`

5. or you want to gen a static lib and dynamic lib, for example: by using `ar -rcs libTest.a -o Test.o`, and then use static lib to gen a exectable file `gcc demo.o libTest.a -o main`

6. gen a shared lib by using `gcc -shared example.o example_wrap.o -o example.so`, however you need to know what kind of obj file that is needed to compile as shared lib

7. so be more advanced, we like to use `cmake` or other build systems to make a better project for many files

what is more about gcc `options`

  1. use -l to link a lib for example I want to use lib---math, using `-lm` 数学库的文件名是 libm.a,前缀lib和后缀.a是标准的,m是基本名称

  1. 使用-L选项,为 GCC 增加另一个搜索链接库的目录

  1. gcc main.c -o main.out -L/usr/lib -lm

  1. ldconfig -p | grep lua 查看库是否存在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值