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

Will Dicharry wdicharry at stellarscience.com
Wed Aug 26 13:24:07 EDT 2009


kent williams wrote:
> 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?

How are you finding the library?  If you use a find_library command for 
it and you are on Unix, you can search for 'libwhatever.a' before 
searching for 'whatever' and that will find the static library if it 
exists.  See http://www.cmake.org/Bug/view.php?id=1643.

--Will

> 
> Oh the thousands of man-months that get expended wrestling with shared
> libraries ....
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


-- 
Will Dicharry
Software Developer
Stellar Science Ltd Co
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3344 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090826/41e02e74/attachment.bin>


More information about the CMake mailing list