Supply library and not adding lib*.a

83 views Asked by At

I think have seen how to do it somewhere but cannot refind it. Example:

gcc -Ldir -lfoo

I want the linker to look for dir/foo not dir/libfoo.a without having to write dir/foo (there are many file in dir needed and running ar first is clumsy).

EDIT: The manual sais

Add directory dir to the list of directories to be searched for -l

and

The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories

I want the behaviour search in directories given by -L and do not clobber the filename. Is that possible.

EDIT 2:

In the ld manual, I found that -l:foo does exactly what I want, and it happens to in gcc. Is that behaviour officially supported?

1

There are 1 answers

0
Michael Pankov On BEST ANSWER

From ld man page:

   -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.

So use the -l:foo.