在编译文件中包含mingw库 [英] Include mingw libraries in compiled file

查看:338
本文介绍了在编译文件中包含mingw库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cmake生成Eclipse CDT MinGW项目。 (Eclipse Version Kepler)

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

这是我的Cmakelist:

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})

代码编译运行没有问题我的电脑,但在其他电脑,它不运行。某些dll像 libgcc_s_dw2-1.dll 是必需的。我在我的电脑里找到这个DLL,我发现它在 C:\MinGW\bin 。为了解决这个问题,我复制了这个文件夹的内容在其他电脑和exe文件最后运行。
然而,我想知道是否有更好的方法运行exe文件在任何Windows PC添加这些库在编译过程中。

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.

我应该让编译器链接到一个静态库。在Eclipse中,我试图在属性> C / C ++包括路径和符号和项目路径>库下添加dll,但它不工作。我试图修改CmakeList,但它也不工作。

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.

我不知道为什么这个问题,如何包括 C:\ MinGW \bin

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

非常感谢任何帮助

推荐答案

是的,有一种方法。对于纯C代码:

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

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

对于C ++代码:

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

这篇关于在编译文件中包含mingw库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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