关于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.
这个选项是支持动态链接,这个也是默认的选项,不用指定。