[CMake] statically linking

Michael Wild themiwi at gmail.com
Fri Feb 12 07:11:41 EST 2010


On 12. Feb, 2010, at 12:46 , burckhardt at itis.ethz.ch wrote:

> Hi,
> 
> could you please tell me how I can force cmake to link all libraries statically?
> 
> Thank you very much,
> 
> Kathrin


Just pass the full paths of the static libraries to TARGET_LINK_LIBRARIES. If you're using FIND_PACKAGE to find the libraries, you're currently out of luck, because there is no way to tell it that you only want the static libraries. Also, on Windows it is not easy to determine whether a .lib file really is a static library or just an import-library for a DLL.

If you insist on -lname style linking, some compilers (e.g. GCC) on some systems take the -static option. But usually, this is more like a request, and e.g. on Mac OS X requires that ALL libraries must be static, which cannot be done since libSystem.dylib and crt0.o are not available in static form.

HTH

Michael


More information about the CMake mailing list