- 论坛徽章:
- 0
|
gcc可以间接调用ld,通过参数-Wl来完成,放在-Wl后的参数gcc不处理,交由ld处理:
gcc –Wl,-startgroup foo.o bar.o –Wl,-endgroup
等同:
ld -startgroup foo.o bar.o -endgroup
Ld选项:
-b TARGET或--format TARGET 设置目标文件的文件格式
-e ADDR或—entry ADDR 设置执行程序开始地址
-E 或 –export-dynamic 当创建使用动态链接库的程序时,把所有符号加入动态符号表。
-EB /–EL 链接大端/小端格式的目标文件
-I LIBNAMe或—library LIBNAME 创建执行程序要链接的库文件
-L DIRCTIONARY或—library path DIRCTIONARY 寻找要链接的库文件时的搜索路径
-M或—print map 把符号的地址映射关系输出到屏幕
-o FILE或---output FILE 生成的目标文件
-O LEVEL 优化级别
-r或-i或—relocatable 生成可重定位(relocatable)的输出文件,这种文件可以作物ld的输入文件。
-s或—strip-all 去除输出文件中所有符号信息
-S或—strip-debug 去除输出文件中的调试符号信息
--strip-discarded 去除discarded节(section)中的符号信息
--no-strip-discarded 不…………
-t或—trace Trace File opens
-T FILE或—script FILE 读链接描述文件名,以确定符号等的定位地址
-u SYMBOL或—undefined SYMBOL 不定义SYMBOL
-x或—discard-all 去掉所有局部(local)符号信息
-X或—discard-locals 去掉临时的局部符号信息,默认选项
--discard-none 不去掉局部局部符号信息
-(archives)或者—start-group archives –end-group 参数中间的目标文件会被ld反复搜索,对相互交叉引用的目标文件很有用
-Bdynamic或-dy或-non_shared或-static 用静态链接库
-Bstatic或-dn或-call_shared 用动态链接库
--check-section 检查个section是否地址重叠,默认选项
--no-check-section …………
--cref 输出交叉参考引用表
-MAP FILE 把符号映射关系输出到文件
-rpath PATH设置运行是动态链接路径
-rpath-link PATH 设置链接是动态链接搜索路径
-shared或-Bshareable 创建动态链接库
-pie或—pic-executive 创建位置无关执行程序
--stats 暑促内存使用统计
--section-start SECTION=ADDR设置节SECTION启示地址
--------------------------------------------------------------------
-nostartfiles
Do not use the standard system startup files when linking. The standard system libraries are used normally, unless `-nostdlib' or `-nodefaultlibs'is used.
-nodefaultlibs
Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker. The standard startup files are used normally, unless `-nostartfiles' is used. The compiler may generate calls to memcmp, memset, and memcpy for System V (and ISO C) environments or to bcopy and bzero for BSD environments. These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.
-nostdlib
Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker. The compiler may generate calls to memcmp, memset, and memcpy for System V (and ISO C) environments or to bcopy and bzero for BSD environments. These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.
One of the standard libraries bypassed by `-nostdlib' and `-nodefaultlibs' is `libgcc.a', a library of internal subroutines that GCC uses to overcome shortcomings of particular machines, or special needs for some languages. (Note:
Interfacing to GCC Output
, for more discussion of `libgcc.a'.) In most cases, you need `libgcc.a' even when you want to avoid other standard libraries. In other words,when you specify `-nostdlib' or `-nodefaultlibs' you should usually specify `-lgcc' as well. This ensures that you have no unresolved references to internal GCC library subroutines. (For example, `__main', used to ensure C++ constructors will be called; Note:
`collect2'
..)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/42111/showart_386864.html |
|