MinGW .exe需要几个gcc dll,不管代码? [英] MinGW .exe requires a few gcc dll's regardless of the code?
问题描述
使用MinGW编译时,我必须在运行exe之前从MinGW bin目录复制某些dll文件(即使使用-static和/或-static-libstdc ++)。
我改变了吗?是否有一个特殊的MinGW构建,我必须使用?最终我想能够运行程序,只有exe在目录中(没有Windows环境变量设置。)这些文件是:
-
- libgcc_s_seh-1.dll
- libwinpthread-1.dll
- 打开代码: :
- 选择文件 - > New->项目 - >控制台
- 填写项目Hello World li>
- 右键单击Project-> Build Options ...-> Hello World(Root target) - > Other Options
- 输入-static
- CTRL-F9:Build Project(未执行)
- 导航到,
- 当一个消息弹出说Error:libstdc ++ - 6.dll从您的计算机丢失时,单击确定。
- 将/ minGW / bin /目录中的libstdc ++ - 6.dll复制到Hello World.exe目录中。
- 运行Hello World.exe
- 单击确定出现错误:libgcc_s_seh-1.dll从您的计算机丢失。
- 将libgcc_s_seh-1.dll复制到Hello World.exe目录中。
- 重复并最终复制libwinpthread-1.dll。
-
查看消息
Hello World!
ul>
这里是步骤完整列表:
编辑
我的命令行是:
g ++。exe -Wall -fexceptions -static -static-libgcc -static-libstdc ++ -g -static-libgcc -static-libstdc ++ -L。 -cC:\Users\ ______ \Desktop\Hello World\main.cpp-o obj\Debug\main.o
g ++。exe -obin\Debug\\ \\Hello World.exeobj \Debug\main.o
以上。为了安全起见,代码是:
// main.cpp
#include< iostream>
using namespace std;
int main()
{
cout< 你好,世界! << endl;
return 0;
}
错误!
转到 main.cpp 文件所在的目录,然后尝试以下操作。
g ++。exe -Wall -c -g main.cpp -o obj\\ \\Debug\main.o
g ++。exe -static -static-libgcc -static-libstdc ++ -obin\Debug\Hello World.exeobj\Debug\main.o
那么你将不再需要复制DLL(对于Hello World程序)。
其他备注:
MinGW安装说明建议设置
c:\minGW; c:\MinGW\bin;
到PATH环境变量。
通常
-static -static-libgcc -static-libstdc ++
链接器选项应该工作(一次尝试所有3个)。但不适用于 libwinpthread-1.dll
。
另外,尝试 code>,然后重新编译。
没有-static-something命令。
库
对于其他库,与-static,然后列出要包含单独的命令,即-lpthread的库。
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:
- libstdc++-6.dll
- libgcc_s_seh-1.dll
- libwinpthread-1.dll
And here is the complete list of step's I fallow:
- Open Up Code::Blocks
- Select "File->New->Project->Console"
- Fill out the project settings for project "Hello World"
- Right click Project->Build Options...->Hello World (Root target)->Other Options
- Enter "-static" (or "-static-libstdc++") under the already set "-fexceptions"
- CTRL-F9 : Build Project (Without executing)
- Navigate to, in Windows Explorer, and run the built "Hello World.exe" file.
- Click "OK" when a message pop's up saying "Error: libstdc++-6.dll is missing from your computer."
- Copy "libstdc++-6.dll" from the /MinGW/bin/ directory, into the "Hello World.exe" directory.
- Run "Hello World.exe"
- Click "OK" for the message saying "Error: libgcc_s_seh-1.dll is missing from your computer."
- Copy "libgcc_s_seh-1.dll" into the "Hello World.exe" directory.
- Repeat and end up copying "libwinpthread-1.dll" over aswell.
View the message
Hello World!
Edit: My command line is:
g++.exe -Wall -fexceptions -static -static-libgcc -static-libstdc++ -g -static-libgcc -static-libstdc++ -L. -c "C:\Users\______\Desktop\Hello World\main.cpp" -o obj\Debug\main.o
g++.exe -o "bin\Debug\Hello World.exe" obj\Debug\main.o
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;
}
Your commands are wrong !
Go to the directory where your main.cpp file is, and try the following.
g++.exe -Wall -c -g main.cpp -o obj\Debug\main.o
g++.exe -static -static-libgcc -static-libstdc++ -o "bin\Debug\Hello World.exe" obj\Debug\main.o
then you'll no longer need to copy the DLLs (for your Hello World program).
Other notes:
The MinGW installation instructions recommends setting
c:\minGW;c:\MinGW\bin;
to the PATH environment variable.
Normally the
-static -static-libgcc -static-libstdc++
linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll
.
Also, try to clean
before recompiling.
There's no "-static-something" command.
Only standard libraries libgcc and libstdc++ can be set to static linking.
For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, i.e. "-lpthread".
这篇关于MinGW .exe需要几个gcc dll,不管代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!