[CMake] Static linking and find_library

Jed Brown jed at 59A2.org
Fri May 8 09:50:26 EDT 2009


Denis Scherbakov wrote:

> In general, linking statically is a very bad idea.

Not always though.  There are many reasons for linking statically
including distributing an app that uses a small part of a library
without requiring users to have the whole thing, running on compute
nodes that do not support shared libs, and occasional performance
benefits from position-dependent code.

It is really annoying to have to make sure you have an environment in
which no shared libs can be found just to link statically.  Very few
Find* modules work correctly with static libs anyway, so it's a much
bigger ball of wax than just a tweak to find_library.

> You don't need to. -static option for gcc will make the trick and gcc
> will automatically pick *.a instead of *.so, if it exists.

Sure, if the link line has

  -static -lfoo

but you get an error if you have

  -static /path/to/foo.so

which is the way CMake does it.

Jed

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090508/2a177112/attachment.pgp>


More information about the CMake mailing list