0

我想已经在某个地方看到了如何做到这一点,但无法重新找到它。例子:

gcc -Ldir -lfoo

我希望链接器无需编写 dir/foo 即可查找 dir/foo 而不是 dir/libfoo.a (dir 中有很多文件需要并且首先运行 ar 很笨拙)。

编辑:手册说

将目录 dir 添加到要搜索的目录列表中 -l

使用 -l 选项和指定文件名的唯一区别是 -l 用“lib”和“.a”包围库并搜索多个目录

我希望在-L 给出的目录中进行行为搜索,并且不要破坏文件名。那可能吗。

编辑2:

在 ld 手册中,我发现 -l:foo 完全符合我的要求,而且它恰好在 gcc 中。这种行为是否得到官方支持?

4

1 回答 1

0

ld手册页:

   -l namespec
   --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, otherwise 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.

所以使用-l:foo.

于 2013-12-30T13:57:09.213 回答