[Bug web/77275] Description of -l option refers only to static libraries, not dynamic/shared libraries

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Aug 16 22:44:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77275

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-08-16
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Tom Payerle from comment #0)
> These should be corrected to include shared libraries, which may also be
> specified by the -l option.  It would probably be good to add something
> along the lines of how the compiler selects if multiple files matching ---

The compiler doesn't select anything, the linker does. GCC just passes the
option directly to the linker.

> my experience is .so files are preferred to .a, but not sure if all library
> directories are searched for .so, then all searched for .a, or if each
> library directory in order is searched for .so then .a.  Assuming the
> latter, something like
> <quote>
> The linker searches a standard list of directories, in order, for the first
> matching shared library (actually a file named liblibrary.so) or standard
> library (actually a file named liblibrary.a) that is found.  If a matching
> shared library and static library are found in the same directory, the
> shared library is preferred.
> </quote>

That's not entirely accurate, the precise semantics depend on the linker, which
is not part of GCC and varies from platform to platform.

> The second line could be changed to something like
> <quote>
> The only difference between using an -l option and specifying a file name is
> that -l surrounds library with ‘lib’ and either '.so' and ‘.a’  and searches
> several directories
> </quote>

Or .dylib, or other OS-specific extensions.

I think it would be better to just say the details depend on the linker.


More information about the Gcc-bugs mailing list