如何使用CMake安装GCC运行时库? [英] How can I install GCC runtime libraries with CMake?

查看:127
本文介绍了如何使用CMake安装GCC运行时库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编译了一个C ++程序,并且可以在我的计算机上正常运行,但是如果我的朋友尝试启动该程序,它说libgcc_s_sw2-1.dll丢失了.如何使用CMake在程序中包含所有必需的GCC运行时库?

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?

推荐答案

正如rubenvb正确回答:libgcc是必需的,否则您应该将CMAKE_EXE_LINKER_FLAGS=-static添加到CMakeLists.txt中.

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

或者,您可以尝试在MinGW安装中找到libgcc_s_sw2-1.dll,并使用 CPack 集成.

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 )

这篇关于如何使用CMake安装GCC运行时库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆