When linking against libraries using the -l
option (say -lfoo
), gcc will prefer a shared object to a static library if both are found (will prefer libfoo.so
to libfoo.a
). Is there a way to make gcc prefer the static library, if both are found?
The issue I'm trying to solve is the following: I'm creating a plugin for an application (the flight simulator called X-Plane), with the following constraints:
/usr/lib
or /usr/lib32
:
LD_PRELOAD
or LD_LIBRARY_PATH
to find shared objects shipped with my pluginto solve the above constraints, a possible solution is to link the generated shared object against static, 32 bit versions of all non-trivial libraries used. but, when installing such libraries, usually both static and dynamic versions are installed, and thus gcc will always link against the shared object instead of the static library.
of course, moving / removing / deleting the shared objects in question, and just leaving the static libraries in say /usr/lib32
, is a work-around, but it is not a nice one
note:
-Wl,-static -lfoo -Wl,-Bdynamic,
but didn't bring the expected results-l:libfoo.a
as well, but this didn't bring the expected results eitherYou can specify the full path to the static libs without the -l
flag to link with those.
gcc ... source.c ... /usr/lib32/libmysuperlib.a ...