且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MinGW需要部署哪些文件?

更新时间:2023-11-14 19:21:58

首先,请确保您确实在构建本机(MinGW)Windows应用程序.您使用的编译器应位于/mingw64/bin//mingw32/bin中.运行which gcc以确保您使用的编译器正确.许多MSYS2问题归结为人们不知道要使用哪个编译器,所以我总是提到它.

First of all, make sure you are actually building a native (MinGW) Windows application. The compiler you are using should be located in /mingw64/bin/ or /mingw32/bin. Run which gcc to make sure you are using the right compiler. Lots of MSYS2 problems boil down to people not knowing which compiler to use, so I always mention it.

所需的DLL完全由程序使用的库以及编译方式决定.因此,我不能仅告诉您所需的DLL.相反,我会帮助您自己解决问题.

The DLLs you need are determined by exactly what libraries your program uses and how it was compiled. So I can't just tell you what DLLs you will need. Instead, I will help you figure it out on your own.

找出这一点的实验方法是只提取编译后的可执行文件,将其移动到MSYS2之外的其他文件夹中,然后尝试通过双击来运行它.它可能会抱怨某些DLL丢失.将该DLL从MSYS2中的相应bin目录(/mingw64/bin/mingw32/bin)复制到带有可执行文件的目录中.重复此过程,直到您的程序成功运行.请注意,我假设MSYS2或其他具有类似DLL的程序不在您的PATH上.您可能需要暂时减少PATH中的文件夹数量,以确保正确执行此操作.例如,您可以尝试在运行set PATH=后从命令提示符运行该程序.

The experimental method to figure this out is to just take the executable file you compiled, move it to a different folder outside of MSYS2, and try to run it by double-clicking on it. It will probably complain about some DLL missing. Copy that DLL from the appropriate bin directory inside MSYS2 (/mingw64/bin or /mingw32/bin) into the directory with your executable. Repeat this until your program runs successfully. Note that I am assuming that MSYS2 or other programs with similar DLLs are not on your PATH. You might want to reduce the number of folders in your PATH temporarily to be sure you are doing this correctly. For example, you could try running the program from a Command Prompt after running set PATH=.

我经常使用的另一种方法是在 Dependency Walker 中打开可执行文件,然后直接查看它包含哪些DLL.取决于.

Another method that I often use is to open my executable in Dependency Walker and see what DLLs it directly depends on.

请注意,在极少数情况下,您可能有一个在运行时而不是在程序启动时加载的DLL.我上面提到的方法无法检测到这种情况,因此没有通用的机制.

Please note that on rare occasions, you might have a DLL that gets loaded at run time instead of when the program starts. The methods I mentioned above cannot detect that, and there is no general mechanism to do so.

文件libstdc++-6.dll是GCC的libstdc ++.它实现了C ++标准库,提供了std::string之类的东西. "VC ++ 6.0可再发行"将是某些Microsoft产品,它与众不同.

The file libstdc++-6.dll is GCC's libstdc++. It implements the C++ standard library, providing things like std::string. The "VC++ 6.0 redistributable" would be some Microsoft product, which is very different.

您的第二个问题不是问题.也许某些库是静态链接而不是动态链接.

Your second question is not a question. Maybe some of the libraries were statically linked instead of dynamically linked.

我不知道有什么好的方法来读取静态库文件(如libgrt.a)的依赖项.静态库只是一堆尚未链接的对象,因此静态库仅包含需要的未定义符号列表,但它不知道最终将由哪个共享库或静态库提供这些符号.我建议将静态库编译为可执行文件.

I don't know of any good way to read the dependencies of a static library file like libgrt.a. Static libraries are just a bundle of objects that have not been linked yet so a static library just has lists of undefined symbols that it needs, but it does not know which shared or static library will end up providing those symbols. I suggest compiling the static library it into an executable.