在拜读了刘欢所写的编译和链接那点事后,对编译和链接有了深一步的理解,所谓编译链接即是将无法直接运行的高级语言等转化为计算机可以直接识别的机器语言必不可少的步骤,根据流程画与理解出了gcc编译器的四个过程以及所做工作:
gcc分为四个步骤:预处理(cpp)、编译(cc1)、汇编(as)、链接(ld)。
- 预处理:头文件展开,宏定义展开,注释替换等,这里的展开是将宏定义所有的展开。
extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__));
# 840 "/usr/include/stdio.h" 3 4
extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 868 "/usr/include/stdio.h" 3 4
# 2 "Helloworld.c" 2
# 3 "Helloworld.c"
void main(void)
{
printf("helloworld!\n");
}
宏定义为#in