gcc迁移手册

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 查看库是否存在

你可能感兴趣的:(为c++使用cmake,linux)