[CMake] Using static, -static-libgcc -static-libstdc++ flags and linking winpthread

Andres Zarza Davila andres.zarzadavila at student.uclouvain.be
Thu Aug 9 06:24:58 EDT 2018


Good afternoon.

We are using CMake to build an open source project. We would like to build it on Windows. For that purpose, we use MingW.
However, we have trouble linking three libraries :

  *   libstdc++-6.dll
  *   libwinpthread-1.dll
  *   libgcc_s_seh-1.dll
To solve this, we decided to link all three statically. In order to do so, we added the following to our main CMakeLists.txt [1]:

    set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CSS_STANDARD_LIBRARIES}")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")

Is this the correct way to proceed in CMake ? Are these the right variables and flags to set ? Do we have to use two different cmake variables to achieve our goal ?

Any hints on improving this CMakeLists.txt is welcome.
Thanks.

Andres.

[1]: https://github.com/azarzadavila/mozart2/blob/d086c4b560472a29a7312e4f291bbc5b3a423414/CMakeLists.txt#L41-L63
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180809/149831dd/attachment.html>


More information about the CMake mailing list