Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install GCC runtime libraries with CMake?

Tags:

gcc

mingw

cmake

I've compiled a C++ program and it's perfectly working on my computer, but if my friend tries to launch the program, it says libgcc_s_sw2-1.dll is missing. How I can include all the required GCC runtime libraries with the program using CMake?

like image 822
Vlad Markushin Avatar asked Oct 21 '12 05:10

Vlad Markushin


2 Answers

As rubenvb correctly answers: libgcc is required or you should add CMAKE_EXE_LINKER_FLAGS=-static to your CMakeLists.txt.

As an alternative, you could try to find libgcc_s_sw2-1.dll in your MinGW installation and "package" it with your installation using InstallRequiredSystemLibraries. This integrates nicely with CPack as well.

E.g. in my own code, I have:

if( MINGW )
    message( STATUS "    Installing system-libraries: MinGW DLLs." )
    get_filename_component( Mingw_Path ${CMAKE_CXX_COMPILER} PATH )
    set( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${Mingw_Path}/mingwm10.dll ${Mingw_Path}/libgcc_s_dw2-1.dll ${Mingw_Path}/libstdc++-6.dll )
endif( MINGW )
include( InstallRequiredSystemLibraries )

Later on, in the part which prepares an install or package:

# Actually install it when make install is called.
# Note, this works with CPack
if( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS )
    install( PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION bin COMPONENT System )
endif( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS )
like image 80
André Avatar answered Sep 30 '22 03:09

André


The libgcc dll is required by all programs compiled with GCC. If you don't want to redistribute this DLL with your program, you must link statically by passing -static to the linker, or in CMake:

CMAKE_EXE_LINKER_FLAGS=-static

This is specific for GCC.

like image 26
rubenvb Avatar answered Sep 30 '22 05:09

rubenvb