[CMake] linking static vs dynamic

Michael Hertling mhertling at online.de
Sat Feb 12 17:11:31 EST 2011


On 02/12/2011 09:39 PM, Andreas Pakulat wrote:
> On 12.02.11 21:20:58, Dominik Szczerba wrote:
>> I never actually saw a solution to this problem in cmake:
>> I need to link (independent constraint from above) with libguide.a and
>> not libguide.so (in intel compiler, does not matter much), but both
>> are available, and cmake always takes the shared one when given
>> "guide" as the desired library to be linked.
>> Is there an elegant way of static linking (other than -static passed
>> to the linker for static linking of everything) of this particular lib
>> other than hacking (like deleting the .so from the folder)?
> 
> No, i.e. no elegant way. What you can do is force cmake to search only
> for .a files by setting a cmake variable, unfortunately I don't remember
> which one and can't easily find it right now. The archive of this list
> has more info as well as the cmake manual or the FAQ on the cmake
> website.
> 
> Andreas

Hi Dominik,

it's CMAKE_FIND_LIBRARY_SUFFIXES; setting it to ".a" on *nix makes
FIND_LIBRARY() search for static libraries only. It can be set to
its original value at any time to restore the previous behaviour.

However, if you know that you're looking exactly for libguide.a and
have control over the FIND_LIBRARY() call, i.e. it's not buried in a
find module or config file, you should follow Alexander's advice, use
the library's full name in FIND_LIBRARY() and pass the latter's result
to TARGET_LINK_LIBRARIES().

Regards,

Michael


More information about the CMake mailing list