Using static, -static-libgcc -static-libstdc++ flags and linking winpthread

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Using static, -static-libgcc -static-libstdc++ flags and linking winpthread

Andres Zarza Davila

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.







Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: