|
发表于 2006-7-28 20:43:19
|
显示全部楼层
这个不对吧~~
编译只是生成object
根据《深入理解计算机系统》里面的讲解,
源程序==》预处理器(cpp)==》编译器(ccl)==》汇编器(as)==》链接器(ld)==》可执行文件
也就是说ld将object文件链接到一块。
- wangyao@fisherman:~$ gcc -v hello.c
- 使用内建 specs。
- 目标:i486-linux-gnu
- 配置为:../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu
- 线程模型:posix
- gcc 版本 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
- /usr/lib/gcc/i486-linux-gnu/4.0.4/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=i686 -auxbase hello -version -o /tmp/ccA0iJ3e.s
- 忽略不存在的目录“/usr/local/include/i486-linux-gnu”
- 忽略不存在的目录“/usr/include/i486-linux-gnu”
- #include "..." 搜索从这里开始:
- #include <...> 搜索从这里开始:
- /usr/local/include
- /usr/lib/gcc/i486-linux-gnu/4.0.4/include
- /usr/include
- 搜索列表结束。
- GNU C version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3) (i486-linux-gnu)
- compiled by GNU C version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3).
- GGC 准则:--param ggc-min-expand=63 --param ggc-min-heapsize=63428
- as -V -Qy --32 -o /tmp/ccoNhv8l.o /tmp/ccA0iJ3e.s
- GNU assembler version 2.16.91 (i486-linux-gnu) using BFD version 2.16.91 20060413 Debian GNU/Linux
- /usr/lib/gcc/i486-linux-gnu/4.0.4/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.0.4/crtbegin.o -L/usr/lib/gcc/i486-linux-gnu/4.0.4 -L/usr/lib/gcc/i486-linux-gnu/4.0.4 -L/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../lib -L/usr/lib/gcc/i486-linux-gnu/4.0.4/../../.. -L/lib/../lib -L/usr/lib/../lib /tmp/ccoNhv8l.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-linux-gnu/4.0.4/crtend.o /usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../lib/crtn.o
复制代码
在最后,实际上是调用了/lib/ld-linux.so.2进行链接
- wangyao@fisherman:~$ gcc -v -static hello.c
- 使用内建 specs。
- 目标:i486-linux-gnu
- 配置为:../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without -included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --en able-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-aw t=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4. 0-1.4.2.0/jre --enable-mpfr --disable-werror --with-tune=i686 --enable-checking= release i486-linux-gnu
- 线程模型:posix
- gcc 版本 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
- /usr/lib/gcc/i486-linux-gnu/4.0.4/cc1 -quiet -v hello.c -quiet -dumpbase hello. c -mtune=i686 -auxbase hello -version -o /tmp/ccxgWSit.s
- 忽略不存在的目录“/usr/local/include/i486-linux-gnu”
- 忽略不存在的目录“/usr/include/i486-linux-gnu”
- #include "..." 搜索从这里开始:
- #include <...> 搜索从这里开始:
- /usr/local/include
- /usr/lib/gcc/i486-linux-gnu/4.0.4/include
- /usr/include
- 搜索列表结束。
- GNU C version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3) (i486-linux-gnu)
- compiled by GNU C version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3).
- GGC 准则:--param ggc-min-expand=63 --param ggc-min-heapsize=63428
- as -V -Qy --32 -o /tmp/ccWN5yLO.o /tmp/ccxgWSit.s
- GNU assembler version 2.16.91 (i486-linux-gnu) using BFD version 2.16.91 2006041 3 Debian GNU/Linux
- /usr/lib/gcc/i486-linux-gnu/4.0.4/collect2 -m elf_i386 -static /usr/lib/gcc/i48 6-linux-gnu/4.0.4/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.0.4/../.. /../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.0.4/crtbeginT.o -L/usr/lib/gcc/i 486-linux-gnu/4.0.4 -L/usr/lib/gcc/i486-linux-gnu/4.0.4 -L/usr/lib/gcc/i486-linu x-gnu/4.0.4/../../../../lib -L/usr/lib/gcc/i486-linux-gnu/4.0.4/../../.. -L/lib/ ../lib -L/usr/lib/../lib /tmp/ccWN5yLO.o --start-group -lgcc -lgcc_eh -lc --end- group /usr/lib/gcc/i486-linux-gnu/4.0.4/crtend.o /usr/lib/gcc/i486-linux-gnu/4.0 .4/../../../../lib/crtn.o
复制代码
最后没有调用ld-linux.so.2进行链接。
我想问一下,既然ld是编译程序时链接目标文件的,ld-linux.so.2是加载运行时动态链接库的。为什么我们在用gcc进行编译的时候时调用ld-linux.so.2来进行链接目标文件呢???
难道是动态编译的问题吗?动态编译时采用ld-linux.so.2,静态编译时采用ld?? |
|