[CMake] Static linking and find_library

Marcel Loose loose at astron.nl
Tue Apr 28 07:44:52 EDT 2009


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?

Best regards,
Marcel Loose.






More information about the CMake mailing list