Static linking with libwinpthread

前端 未结 3 2057
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-14 19:42

I try to build program with static linked toolchain libraries. I pass:

LDFLAGS=\"-Wl,-Bstatic -lwinpthread -Wl,-Bdynamic -static-libgcc -static-libstdc++\"
         


        
3条回答
  •  悲&欢浪女
    2021-02-14 20:27

    Not ideal but if you do not mind plonking your runtime DLL's in the same directory as your executable, you can add something like this in your CMakeLists.txt file. This will copy the necessary DLL's from the MingW bin directory into the current build directory.

    # ...
    # change to name of your project
    set(TARGET_NAME ${PROJECT_NAME})
    # change to path to your minw bin directory
    set(MINGW_BIN_PATH "C:\\Program Files\ \(x86\)\\mingw-w64\\i686-4.9.2-posix-dwarf-rt_v3-rev1\\mingw32\\bin")
    
    set(LIBGCC_DLL "${MINGW_BIN_PATH}\\libgcc_s_dw2-1.dll")
    add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy
                       ${LIBGCC_DLL} $)
    set(LIBSTDCPP_DLL "${MINGW_BIN_PATH}\\libstdc++-6.dll")
    add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy
                       ${LIBSTDCPP_DLL} $)
     set(LIBWINPTHREAD_DLL "${MINGW_BIN_PATH}\\libwinpthread-1.dll")
     add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy
                        ${LIBWINPTHREAD_DLL} $)
    

提交回复
热议问题