There is also -l:libstatic1.a
(minus l colon) variant of -l option in gcc which can be used to link static library (Thanks to https://stackoverflow.com/a/20728782). Is it documented? Not in the official documentation of gcc (which is not exact for shared libs too): https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
-llibrary -l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.) ... 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.
The binutils ld doc describes it. The -lname
option will do search for libname.so
then for libname.a
adding lib prefix and .so
(if enabled at the moment) or .a
suffix. But -l:name
option will only search exactly for the name specified:
https://sourceware.org/binutils/docs/ld/Options.html
-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. Ifnamespec
is of the form:filename
, ld will search the library path for a file calledfilename
, otherwise it will search the library path for a file calledlibnamespec.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 calledlibnamespec.so
before searching for one calledlibnamespec.a
. (By convention, a.so
extension indicates a shared library.) Note that this behavior does not apply to:filename
, which always specifies a file calledfilename
.The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.
See the
-(
option for a way to force the linker to search archives multiple times.You may list the same archive multiple times on the command line.
This type of archive searching is standard for Unix linkers. However, if you are using ld on AIX, note that it is different from the behaviour of the AIX linker.
The variant -l:namespec
is documented since 2.18 version of binutils (2007): https://sourceware.org/binutils/docs-2.18/ld/Options.html