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

我编写了一个简单的HelloWorld控制台应用程序,并使用以下命令之一使用MinGW编译器在
Windows 7上编译它:

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

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

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

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

最佳答案 它在某个阶段的FAQ中,但现在我似乎只在
this page找到它:

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

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.

试试这个,

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