C++ 程序找不到 libgcc_s_dw2-1.dll

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4984612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:05:29  来源:igfitidea点击:

Program can't find libgcc_s_dw2-1.dll

c++mingwcodeblocksstatic-linking

提问by Greg Treleaven

Possible Duplicate:
The program can't start because libgcc_s_dw2-1.dll is missing

可能重复:
程序无法启动,因为缺少 libgcc_s_dw2-1.dll

I'm using Code::Blocks and MinGW 4.4 (I think) compiler to create a C++ project. I get this system error if I run it from its directory, but not from within Code::Blocks.

我正在使用 Code::Blocks 和 MinGW 4.4(我认为)编译器来创建 C++ 项目。如果我从它的目录运行它,而不是从 Code::Blocks 中运行它,我会收到这个系统错误。

The program can't start because libgcc_s_dw2-1.dll is missing from your computer.  Try reinstalling the program to fix this problem.

In this posthardmath said to add -static-libgccto the compiler flags, linking to the dll statically. When I tried this the error still occurred. I could get it to work by adding the MinGW bin directory to my computer's Path variable, but I plan on distributing my program across the internet.

这篇文章中,hardmath 说要添加-static-libgcc到编译器标志,静态链接到 dll。当我尝试这个时,错误仍然发生。我可以通过将 MinGW bin 目录添加到我计算机的 Path 变量来使其工作,但我计划在 Internet 上分发我的程序。

The issue only appeared after updating to the latest G++ compiler. What's the reason for this solution working for everyone else apart from me?

该问题仅在更新到最新的 G++ 编译器后才出现。除了我之外,此解决方案适用于其他所有人的原因是什么?

回答by rubenvb

The link commandline argument -static-libgccshould work. Another variant you could try is plain -static.

链接命令行参数-static-libgcc应该可以工作。您可以尝试的另一个变体是 plain -static

If you don't want to worry about this, and still want to redistribute your binary, just copy the relevant dll from MinGW's bin directory and place it alongside your executable. This is common practice and works as advertised.

如果您不想为此担心,并且仍想重新分发您的二进制文件,只需从 MinGW 的 bin 目录中复制相关的 dll 并将其放在您的可执行文件旁边。这是常见的做法,并且如宣传的那样有效。