[CMake] Static linking and find_library

Philip Lowman philip at yhbt.com
Sat May 2 20:54:17 EDT 2009


On Tue, Apr 28, 2009 at 7:44 AM, Marcel Loose <loose at astron.nl> wrote:

> Hi all,
>
> I've been searching the documentation, but couldn't find a way to
> specify that I want to create a statically linked binary. The only
> platform-specific and even compiler-specific answer I could find was to
> add "-static" to CMAKE_EXE_LINKER_FLAGS.
>
> Now this solves only part of the problem. Suppose I want to link against
> the static library of some 3rd party package Foo. Suppose that Foo only
> supplies a libfoo.so (but I'm unaware of this fact).
>
> When I search for the foo-library using find_library(foo_library foo) I
> find a match, so CMake happily trods on. But when I type 'make', I'll
> discover to my dismay that the system cannot create a  statically linked
> executable, because it cannot find libfoo.a. Bummer!
>
> So my question is twofold:
>
> 1) Is there a generic platform- and compiler-independent way to specify
> that you want to create a statically linked executable?
>
> 2) How can I persuade find_library() to only search for static
> libraries?


Not sure on the first.  For the second, provided you're running on an OS
that has different file extensions for static vs. shared libraries and the
name of the library is otherwise the same, you can use the
CMAKE_FIND_LIBRARY_SUFFIXES variable.

Make sure you restore the value of CMAKE_FIND_LIBRARY_SUFFIXES after you are
done making calls to find_library().

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


More information about the CMake mailing list