[CMake] Static linking and find_library

Denis Scherbakov denis_scherbakov at yahoo.com
Fri May 8 09:33:11 EDT 2009



> 1) Is there a generic platform- and compiler-independent
> way to specify
> that you want to create a statically linked executable?

find /usr/share/cmake -type f | grep -E '\.cmake$' | xargs grep -i -n -H '\-static'

No matches == there is no cross-platform way to specify that you want static exectuable.

I think this is a bug, but since, we are talking about static executables, you may want to read http://people.redhat.com/drepper/no_static_linking.html

In general, linking statically is a very bad idea.
Moreover, if your code is not GPL, you're not allowed to link against libc/libgcc statically. It is direct GPL violation.
 
> 2) How can I persuade find_library() to only search for
> static
> libraries?

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.



      


More information about the CMake mailing list