使用 MinGW 编译时,我必须在 exe 运行之前从 MinGW bin 目录中复制某些 dll 文件(即使使用-static"和/或-static-libstdc++"也是如此.)我该如何改变?是否有我必须使用的特殊版本的 MinGW?最终,我希望能够只使用目录中的 exe(并且没有设置 Windows 环境变量)来运行程序.这些文件是:
When compiling with MinGW, I have to copy over certain dll files from the MinGW bin directory before the exe will run (Even when using "-static" and/or "-static-libstdc++".) How do I change that? Is there a special build of MinGW that I have to use? Ultimately I want to be able to run the program with nothing but the exe in the directory (and no windows environment variables set.) These File's are:
这是我休耕的完整步骤列表:
And here is the complete list of step's I fallow:
查看消息
View the message
Hello World!
我的命令行是:
g++.exe -Wall -fexceptions -static -static-libgcc -static-libstdc++ -g -static-libgcc -static-libstdc++ -L. -c "C:Users\______DesktopHello Worldmain.cpp" -o objDebugmain.o
g++.exe -o "binDebugHello World.exe" objDebugmain.o
需要上面提到的所有dll文件.而且,为了安全起见,代码是:
With all the dll files mentioned above required. And, just to be safe, the code is:
// main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
你的命令错了!
转到 main.cpp 文件所在的目录,然后尝试以下操作.
Go to the directory where your main.cpp file is, and try the following.
g++.exe -Wall -c -g main.cpp -o objDebugmain.o
g++.exe -static -static-libgcc -static-libstdc++ -o "binDebugHello World.exe" objDebugmain.o
那么您将不再需要复制 DLL(用于您的 Hello World 程序).
then you'll no longer need to copy the DLLs (for your Hello World program).
其他注意事项:
MinGW安装说明推荐设置
The MinGW installation instructions recommends setting
c:minGW;c:MinGWin;
到 PATH 环境变量.
to the PATH environment variable.
通常是
-static -static-libgcc -static-libstdc++
链接器选项应该可以工作(一次尝试所有 3 个).但不适用于 libwinpthread-1.dll
.
linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll
.
另外,在重新编译之前尝试clean
.
Also, try to clean
before recompiling.
没有-static-something"命令.
There's no "-static-something" command.
只有标准库 libgcc 和 libstdc++ 可以设置为静态链接.
Only standard libraries libgcc and libstdc++ can be set to static linking.
对于其他库,您首先使用-static"切换到静态链接,然后列出要包含在单独命令中的库,即-lpthread".
For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, i.e. "-lpthread".
Cmake 用户应该尝试添加:
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
这篇关于无论代码如何,MinGW .exe 都需要一些 gcc dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!