我是
linux的新手.任何人可以向我解释我的hello world程序的以下详细模式输出?此外,文件crt1.o,crti.o,crtend.o,crtbegin.o和crtn.o和lc和lgcc会做什么?任何其他解释性的联系也是欢迎的.
$gcc -v hello.c Reading specs from /usr/lib/gcc-lib/i686/3.3.1/specs Configured with: ../configure --prefix=/usr Thread model: posix gcc version 3.3.1 /usr/lib/gcc-lib/i686/3.3.1/cc1 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 hello.c -quiet -dumpbase hello.c -auxbase hello -Wall -version -o /tmp/cceCee26.s GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3.1 (i686-pc-linux-gnu) GGC heuristics: --param ggc-min-expand=51 --param ggc-min-heapsize=40036 ignoring nonexistent directory "/usr/i686/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/include /usr/lib/gcc-lib/i686/3.3.1/include /usr/include End of search list. as -V -Qy -o /tmp/ccQynbTm.o /tmp/cceCee26.s GNU assembler version 2.12.90.0.1 (i386-linux) using BFD version 2.12.90.0.1 20020307 Debian/GNU Linux /usr/lib/gcc-lib/i686/3.3.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o -L/usr/lib/gcc-lib/i686/3.3.1 -L/usr/lib/gcc-lib/i686/3.3.1/../../.. /tmp/ccQynbTm.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc-lib/i686/3.3.1/crtend.o /usr/lib/crtn.o
解决方法
第一部分是编译器驱动程序的版本和配置数据(这是gcc二进制文件,实际上并不是编译器本身):
Reading specs from /usr/lib/gcc-lib/i686/3.3.1/specs Configured with: ../configure --prefix=/usr Thread model: posix gcc version 3.3.1
然后它打印它用来调用真正的编译器的命令cc1:
/usr/lib/gcc-lib/i686/3.3.1/cc1 -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 hello.c -quiet -dumpbase hello.c -auxbase hello -Wall -version -o /tmp/cceCee26.s
而cc1打印它的版本和配置信息.
GNU C version 3.3.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3.1 (i686-pc-linux-gnu) GGC heuristics: --param ggc-min-expand=51 --param ggc-min-heapsize=40036
ignoring nonexistent directory "/usr/i686/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/include /usr/lib/gcc-lib/i686/3.3.1/include /usr/include End of search list.
编译器现在完成了,所以gcc告诉你将使用的汇编器命令.
as -V -Qy -o /tmp/ccQynbTm.o /tmp/cceCee26.s
而汇编程序就给出了它的版本信息.
GNU assembler version 2.12.90.0.1 (i386-linux) using BFD version 2.12.90.0.1 20020307 Debian/GNU Linux
汇编器现在完成,所以gcc给出了链接器命令.它使用collect2作为真正的链接器ld的中介,但这并不重要.
/usr/lib/gcc-lib/i686/3.3.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o -L/usr/lib/gcc-lib/i686/3.3.1 -L/usr/lib/gcc-lib/i686/3.3.1/../../.. /tmp/ccQynbTm.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc-lib/i686/3.3.1/crtend.o /usr/lib/crtn.o
“crt”文件是指“C RunTime”.它们是在程序开始时插入的小部分代码,最后一节.他们负责初始化全局变量,堆和堆栈.从main返回后,它们调用atexit函数.另外还有一些.
希望有帮助.