[CMake] How do I tell a program to link against the static version of a library if both static and shared are there.

kent williams nkwmailinglists at gmail.com
Wed Aug 26 12:41:06 EDT 2009


We use the Slicer Execution Model stuff from Slicer3 for command line
processing.  This lets Slicer3 load our programs as modules and
generate user interface panels.

This works really slick EXCEPT for this issue: the utility GenerateCLP
which is needed to convert the command line description XML to C++
header builds shared, and depends on a shared library
libModuleDescriptionParser.so.  This means that GenerateCLP now will
not work unless you add the directory containing the shared library to
LD_LIBRARY_PATH

For a while I just changed the ModuleDescriptionParser CMakeLists.txt
so that it built the library static, but then I ran into a problem
with that: When I needed to link the ModuleDescriptionParser library
into one of my own shared libraries, the link failed because the
static library wasn't compiled for position-independent code (i.e.
-fPIC for gcc).

So I found the trick to build both the shared and static versions in
the FAQ, but  GenerateCLP links to the shared version of the library
when I want it to link to the static version.

Is there a way in CMake to tell it to link GenerateCLP to link
preferentially to the static version of the library?

Oh the thousands of man-months that get expended wrestling with shared
libraries ....


More information about the CMake mailing list