4

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

Alexander Shukaev
  • 16,674
  • 8
  • 70
  • 85
Hank81
  • 43
  • 1
  • 4

1 Answers1

6

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")
Alexander Shukaev
  • 16,674
  • 8
  • 70
  • 85
  • Yes, vielen Dank. It works fine and your answer clear and helpful – Hank81 Nov 04 '13 at 09:11
  • 1
    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 solution – Stewart Aug 17 '17 at 09:38
  • Which compiler and what artifact did you build? Is it a DLL that you build or an executable? – Alexander Shukaev Aug 17 '17 at 11:08
  • 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. – Enzo Jan 02 '23 at 00:01