[CMake] Static linking and find_library

Philip Lowman philip at yhbt.com
Sat May 9 10:19:25 EDT 2009


On Fri, May 8, 2009 at 10:58 AM, Marcel Loose <loose at astron.nl> wrote:

> Hi Denis,
>
> There are definitely cases where you do want to create a statically
> linked executable; for example when running on a massively parallel
> diskless system -- you don't want thousands of compute nodes to load a
> shared library over some NFS link.
>
> Anyway, the real problem with find_library() is, when you have a shared
> library installed, but not the associated static library. In that case,
> the linker will choke while creating a statically linked executable,
> because it cannot find the library it needs.
>
> I guess the only way to solve this is to manually set
> CMAKE_FIND_LIBRARY_SUFFIXES, like FindBoost.cmake does. I wish there
> were a more generic, platform-independent way to do this. Maybe worth a
> feature request?


The big problem is WIN32 where static and shared/import libraries have the
same file extension so they obviously can't go in the same directory.  You
could solve the problem with keywords.  If you forced the keywords to have
actual filenames behind them it would probably make it clear to people at
first glance that they only affect WIN32.  For example:

find_library(FOO NAMES foo STATIC:foo_static.lib SHARED:foo.lib )

Then all you would need is a variable with 4 options to control the
searching
1. prefer shared (default)
2. prefer static
3. require shared
4. require static

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090509/b0ce71f0/attachment.htm>


More information about the CMake mailing list