Include mingw libraries in compiled file
Asked Answered
P

1

5

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

Passementerie answered 18/10, 2013 at 13:19 Comment(0)
Y
9

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")
Yuzik answered 18/10, 2013 at 13:31 Comment(5)
Yes, vielen Dank. It works fine and your answer clear and helpfulPassementerie
Just tried the C++ variant of this. Running the DLL through dependency walker, I still see dependencies on LIBGCC_S_DW2-1.DLL and LIBSTDC++-6.DLL. Doesn't appear to be a catch-all solutionInter
Which compiler and what artifact did you build? Is it a DLL that you build or an executable?Yuzik
the C++ options work for me, I do not see libwinpthread-1.dll, libstdc++-6.dll and libgcc_s_seh-1.dll anymore as dependencies.Astrograph
The C++ option worked for me, thank you!Chapbook

© 2022 - 2024 — McMap. All rights reserved.