Include mingw libraries in compiled file

自古美人都是妖i 提交于 2019-12-07 16:51:52

问题


I am using cmake to generate a Eclipse CDT MinGW Project. (Eclipse Version Kepler)

This is my Cmakelist:

project(IMGTODICOM)

find_package(ITK REQUIRED)

include(${ITK_USE_FILE})

add_executable(IMGTODICOM IMGTODICOM.cxx)

target_link_libraries(IMGTODICOM ITKReview ${ITK_LIBRARIES})

The code compile and run without problem in my computer, but in other PC it does not run. Some dll like libgcc_s_dw2-1.dll are required. I looked for this dll in my computer and I found it in C:\MinGW\bin. To solve the problem I copied the content of this folder in the other PC and the exe file finally run. However, I am wondering if there is a better method to run the exe file in any windows pc adding these libraries in the compilation process.

I was reading and I should make that the compiler link to a static library. In Eclipse I tried to add the dll under properties>C/C++ Include Path and Symbols and under project Path>Libraries, but it does not work. I tried to modify the CmakeList but it also does not work.

I don't know why this problem and how can I include the content of C:\MinGW\bin in the exe file.

Many Thanks for any help


回答1:


Yes, there is a way. For pure C code:

set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static")

For C++ code:

set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")


来源:https://stackoverflow.com/questions/19450722/include-mingw-libraries-in-compiled-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!