[CMake] Problems building statically linked executable
Brad King
brad.king at kitware.com
Mon May 11 13:45:02 EDT 2009
Marcel Loose wrote:
> I'm really struggling to build statically linked executables with CMake
> (also see my previous post with subject: Static linking and
> find_library).
I've answered in that thread.
> Furthermore I added the '-static' flag to the linker with
> SET(CMAKE_EXE_LINKER_FLAGS -static).
Good.
> In the mean time, is there a way to get rid of these spurious
> -Wl,-Bdynamic and -Wl,-Bstatic flags?
CMake is adding those because it doesn't know anything special about -static.
It just assumes that all "-l" options should prefer shared libs in all cases.
You can make sure it ends with -Bstatic with the LINK_SEARCH_END_STATIC
property:
http://www.cmake.org/cmake/help/cmake2.6docs.html#prop_tgt:LINK_SEARCH_END_STATIC
To ensure a static pthread library is chosen, refer to it by name (libpthread.a)
or full path.
-Brad
More information about the CMake
mailing list