ld链接器的链接顺序

 

关于ld链接时寻找库的顺序,文档中给出了权威说法。之前一直是看到别人写的博文这么说,终于找到依据了。

`-lNAMESPEC'

`--library=NAMESPEC'

     Add the archive or object file specified by NAMESPEC to the list

     of files to link.  This option may be used any number of times.

     If NAMESPEC is of the form `:FILENAME', `ld' will search the

     library path for a file called FILENAME, otherise it will search

     the library path for a file called `libNAMESPEC.a'.

 

     On systems which support shared libraries, `ld' may also search for

     files other than `libNAMESPEC.a'.  Specifically, on ELF and SunOS

     systems, `ld' will search a directory for a library called

     `libNAMESPEC.so' before searching for one called `libNAMESPEC.a'.

     (By convention, a `.so' extension indicates a shared library.)

     Note that this behavior does not apply to `:FILENAME', which

     always specifies a file called FILENAME.

 

特别是在ELF和SUNOS系统上,ld会在搜索名为`libNAMESPEC.a'的库之前搜索名为`libNAMESPEC.so' 的库。

也就是说,优先链接动态库。

 

 

 

 

`-Bdynamic'

`-dy'

`-call_shared'

     Link against dynamic libraries.  This is only meaningful on

     platforms for which shared libraries are supported.  This option

     is normally the default on such platforms.  The different variants

     of this option are for compatibility with various systems.  You

     may use this option multiple times on the command line: it affects

     library searching for `-l' options which follow it.

这个选项是支持动态链接,这个也是默认的选项,不用指定。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值