Use -l:
instead of -l
. For example -l:libXYZ.a
to link with libXYZ.a
. Notice the lib
and .a
are written out, as opposed to -lXYZ
which would auto-expand to libXYZ.so
/libXYZ.a
.
It is an option of the GNU ld
linker:
-l namespec
… 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 calledlibnamespec.a
. … on ELF … systems,ld
will search a directory for a library calledlibnamespec.so
before searching for one calledlibnamespec.a
. … Note that this behavior does not apply to:filename
, which always specifies a file called filename.”
(Since binutils 2.18)
Note that this only works with the GNU linker. If your ld
isn’t the GNU one you’re out of luck.