提供库而不添加lib * .a

时间:2013-12-24 11:34:38

标签: gcc linker search-path

我认为已经看到了如何在某个地方做到这一点,但无法重新证明它。例如:

gcc -Ldir -lfoo

我希望链接器在不必编写dir / foo的情况下查找dir / foo而不是dir / libfoo.a(在dir中需要很多文件并且首先运行ar是笨拙的)。

编辑:手册sais

  

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

  

使用-l选项和指定文件名之间的唯一区别是-l围绕带有'lib'和'.a'的库并且搜索多个目录

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

编辑2:

在ld手册中,我发现-l:foo正是我想要的,它恰好出现在gcc中。 这种行为是否得到官方支持?

1 个答案:

答案 0 :(得分: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

相关问题