[CMake] linking with libstdc++ statically

victor.zverovich at gmail.com victor.zverovich at gmail.com
Wed Aug 27 17:19:43 EDT 2014


Hello,

I am trying to link an application with libstdc++ statically on Linux and
OS X. The first attempt was to add -static-libstdc++ to
CMAKE_EXE_LINKER_FLAGS:

  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")

This works on Linux with GCC, but Clang gives the following error on OS X:

  clang: warning: argument unused during compilation: '-static-libstdc++'

Another way that I found is to find the location of static libstdc++
library in the directories given by CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES and
modify
CMAKE_CXX_IMPLICIT_LINK_LIBRARIES.

Is there a better way to link with libstdc++ statically in CMake?

Thanks,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140827/be97db82/attachment-0001.html>


More information about the CMake mailing list