0-15 GCC程序编译

用法:    gcc [...] filenamesbash

例如:    gcc hello.c    ide

输出:    a.out优化

过程:    hello.c 预变异 hello.i 编译后 hello.s 汇编后 hello.o 连接后 hello调试


预编译: 源码

        gcc -E hello.c -o hello.i

编译  : it

        gcc -S hello.i -o hello.s

汇编  : 编译

        gcc -C hello.s -o hello.o

连接  :  class

        gcc    hello.o -o hello


文件格式:gcc

*.c    C语言源码file

*.h    头文件

*.a    库文件

*.o    目标文件

*.C *.cc *.cpp  C++文件

*.s *.S  汇编文件


gcc编译选项:

-o  指定输出可执行文件

-O  对程序进行优化编译

-O2 对程序更好的编译,消耗更多的时间

-c  只编译不链接,输出*.o目标文件

-g  产生gdb所须要的符号,用于调试


Linux系统头文件通常存放于/usr/include中,若头文件存放在当前目录,引用格式为:

        #include "XXX.h"

或者用-I选项指定头文件存放地方,如:

        gcc -I /root hello.c -o hello


预编译的使用:

#define PRINT

#ifdef PRINT

...

#endif

相关文章
相关标签/搜索