在另一台计算机上启动使用MinGW编译的Windows应用程序时,库链接错误

时间:2021-02-17 16:02:33

I wrote a simple HelloWorld console application and compiled it on Windows 7 with MinGW compiler using one of these commands:

我编写了一个简单的HelloWorld控制台应用程序,并使用其中一个命令将其编译在Windows 7上,并使用了其中的一个命令:

gcc -Wall -pedantic Hello.c -o Hello.exe
g++ -Wall -pedantic Hello.cpp -o Hello.exe

However the compiler links some own dynamic libraries into the app and when i copy the executable into another computer with Windows 7, which does not have MinGW installed, i'm getting missing library error. On Linux this problem is solved by package system, which automatically installs all needed libs, but in Windows you surely don't want to tell your users to install MinGW in order to run your program.

但是编译器将一些自己的动态库链接到应用程序中,当我用Windows 7将可执行文件复制到另一台没有安装MinGW的计算机时,我就会丢失库错误。在Linux上,这个问题通过包系统来解决,包系统自动安装所有需要的lib,但是在Windows中,你肯定不想告诉你的用户安装MinGW来运行你的程序。

So my question is: How do i link all libraries properly and what else do i have to do to make my application run independently?

所以我的问题是:我如何正确地链接所有库,我还需要做什么才能使我的应用程序独立运行?

Although i believe, this must be a fundamental problem to all Windows programmers, i have been unable to find any answers on the internet (maybe i just don't know how and what to search).

尽管我相信,这对所有Windows程序员来说都是一个根本性的问题,但我一直无法在互联网上找到任何答案(也许我只是不知道如何搜索以及搜索什么)。

2 个解决方案

#1


2  

It was in the FAQ at some stage, but now I seem to find it only on this page:

在某个阶段的FAQ中,但现在我似乎只在这页上找到它:

Why I get an error about missing libstdc++-6.dll file when running my program?

为什么会有一个关于libstdc++-6丢失的错误。运行我的程序时dll文件?

GCC4 dynamically link to libgcc and libstdc++ libraries by default which means that you need a copy of libgcc_s_dw2-1.dll and libstdc++-6.dll files to run your programs build with the GCC4 version (These files can be found in MinGW\bin directory). To remove these DLL dependencies, statically link the libraries to your application by adding "-static-libgcc -static-libstdc++" to your "Extra linking options" in the project settings.

GCC4在默认情况下会动态链接到libgcc和libstdc+库,这意味着您需要一个libgcc_s_dw2的副本。dll和libstdc + + 6。使用GCC4版本运行程序构建的dll文件(这些文件可以在MinGW\bin目录中找到)。要删除这些DLL依赖项,通过在项目设置中的“额外链接选项”中添加“-static-libgcc -static-libstdc++”,静态地将库链接到应用程序。

Try this,

试试这个,

g++ -static-libgcc -static-libstdc++ -Wall -pedantic Hello.cpp -o Hello.exe

#2


0  

I'm afraid to say that with all of the applications installed on my machine, it's easy to identify which ones were built with MinGW. The telltale sign is a folder filled with libraries.

我恐怕要说的是,在我的机器上安装了所有的应用程序后,很容易识别哪些应用程序是用MinGW构建的。指示符是一个充满库的文件夹。

Check to see if the libraries that you need are distributable, and then simply include them in your .exe directory.

检查您需要的库是否可分发,然后将它们包含在.exe目录中。

Although you may have other applications installed on user's machine, and some of them may contain the libraries that you need, there's a good chance that your application wont be compatible with them. This is why asking your users to install MinGW would be unlikely to work anyways.

尽管您可能在用户的计算机上安装了其他应用程序,其中一些应用程序可能包含您需要的库,但是您的应用程序很可能不会与它们兼容。这就是为什么要求用户安装MinGW无论如何都不太可能工作。

#1


2  

It was in the FAQ at some stage, but now I seem to find it only on this page:

在某个阶段的FAQ中,但现在我似乎只在这页上找到它:

Why I get an error about missing libstdc++-6.dll file when running my program?

为什么会有一个关于libstdc++-6丢失的错误。运行我的程序时dll文件?

GCC4 dynamically link to libgcc and libstdc++ libraries by default which means that you need a copy of libgcc_s_dw2-1.dll and libstdc++-6.dll files to run your programs build with the GCC4 version (These files can be found in MinGW\bin directory). To remove these DLL dependencies, statically link the libraries to your application by adding "-static-libgcc -static-libstdc++" to your "Extra linking options" in the project settings.

GCC4在默认情况下会动态链接到libgcc和libstdc+库,这意味着您需要一个libgcc_s_dw2的副本。dll和libstdc + + 6。使用GCC4版本运行程序构建的dll文件(这些文件可以在MinGW\bin目录中找到)。要删除这些DLL依赖项,通过在项目设置中的“额外链接选项”中添加“-static-libgcc -static-libstdc++”,静态地将库链接到应用程序。

Try this,

试试这个,

g++ -static-libgcc -static-libstdc++ -Wall -pedantic Hello.cpp -o Hello.exe

#2


0  

I'm afraid to say that with all of the applications installed on my machine, it's easy to identify which ones were built with MinGW. The telltale sign is a folder filled with libraries.

我恐怕要说的是,在我的机器上安装了所有的应用程序后,很容易识别哪些应用程序是用MinGW构建的。指示符是一个充满库的文件夹。

Check to see if the libraries that you need are distributable, and then simply include them in your .exe directory.

检查您需要的库是否可分发,然后将它们包含在.exe目录中。

Although you may have other applications installed on user's machine, and some of them may contain the libraries that you need, there's a good chance that your application wont be compatible with them. This is why asking your users to install MinGW would be unlikely to work anyways.

尽管您可能在用户的计算机上安装了其他应用程序,其中一些应用程序可能包含您需要的库,但是您的应用程序很可能不会与它们兼容。这就是为什么要求用户安装MinGW无论如何都不太可能工作。