C++ 程序无法启动,因为缺少 libgcc_s_dw2-1.dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4702732/
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
The program can't start because libgcc_s_dw2-1.dll is missing
提问by xRobot
I have created a simple program in C++ with Code::Blocks.
我用 Code::Blocks 用 C++ 创建了一个简单的程序。
If I run it from Code::Blocks, it works correctly; but if I run it by doubleclicking on the executable file, a window pops up with this message:
如果我从 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.
程序无法启动,因为您的计算机缺少 libgcc_s_dw2-1.dll。
尝试重新安装程序以解决此问题。
So, what is the problem? What do I have to do to fix it?
那么,问题是什么?我该怎么做才能修复它?
回答by hardmath
I believe this is a MinGW/gcc compiler issue, rather than a Microsoft Visual Studio setup.
我相信这是 MinGW/gcc 编译器问题,而不是 Microsoft Visual Studio 设置。
The libgcc_s_dw2-1.dll
should be in the compiler's bin directory. You can add this directory to your PATH environment variable for runtime linking, or you can avoid the problem by adding "-static-libgcc -static-libstdc++" to your compiler flags.
本libgcc_s_dw2-1.dll
应在编译器的bin目录。您可以将此目录添加到您的 PATH 环境变量以进行运行时链接,或者您可以通过将“-static-libgcc -static-libstdc++”添加到您的编译器标志来避免该问题。
If you plan to distribute the executable, the latter probably makes the most sense. If you only plan to run it on your own machine, the changing the PATH environment variable is an attractive option (keeps down the size of the executable).
如果您计划分发可执行文件,后者可能最有意义。如果你只打算在你自己的机器上运行它,改变 PATH 环境变量是一个有吸引力的选择(保持可执行文件的大小)。
Updated:
更新:
Based on feedback from Greg Treleaven (see comments below), I'm adding links to:
根据 Greg Treleaven 的反馈(见下面的评论),我添加了以下链接:
[Screenshot of Code::Blocks "Project build options"]
The latter discussion includes -static-libgcc
and -static-libstdc++
linker options.
后者讨论包括-static-libgcc
和-static-libstdc++
链接器选项。
回答by TommyTom
In Eclipse, you will find it under the project properties > C/C++ Build > Settings > MinGW C++ Linker > Misc
在 Eclipse 中,您会在项目属性 > C/C++ Build > Settings > MinGW C++ Linker > Misc 下找到它
You must add it to the "linker flags" at the top; nowhere else. Then just rebuild.
您必须将其添加到顶部的“链接器标志”中;无处。那就只能重建了。
I have found that linking those statically explodes the size up to 1,400kb even with optimizations. It's 277kb larger compared to just copying over the shared DLLs. It's 388kb larger as well after UPXing everything. Very lose/lose here. Just include the DLLs as the end-user can decide to delete them or not if they have them installed elsewhere.
我发现即使进行了优化,静态链接这些文件也会使大小高达 1,400kb。与仅复制共享 DLL 相比,它大 277kb。在 UPXing 一切之后,它也大了 388kb。在这里很输/输。只需包含 DLL,因为最终用户可以决定是否删除它们,如果他们将它们安装在其他地方。
回答by user1826947
Code::Blocks: add '-static' in settings->compiler->Linker settings->Other linker options.
代码::块:在设置->编译器->链接器设置->其他链接器选项中添加'-static'。
回答by Dave
Find that dll on your PC, and copy it into the same directory your executable is in.
在您的 PC 上找到该 dll,并将其复制到您的可执行文件所在的同一目录中。
回答by fat
回答by rogerdpack
I was able to overcome this by using "gcc" instead of "g++" for my compiler. I know this isn't an option for most people, but thought I'd mention it as a workaround option :)
我能够通过为我的编译器使用“gcc”而不是“g++”来克服这个问题。我知道这对大多数人来说不是一个选择,但我想我会提到它作为一种解决方法:)
回答by Blizz
Copy "libgcc_s_dw2-1.dll" to were make.exe is. (If you are using Msys, copy it to \msys\bin) Make sure that the path to make.exe is set in the env. PATH (if make.exe is in a folder "bin", most likely, and you have msys, it's \msys\bin) Compile, rund, debug, etc. happy.
将“libgcc_s_dw2-1.dll”复制到make.exe。(如果您使用的是 Msys,请将其复制到 \msys\bin)确保在 env 中设置了 make.exe 的路径。PATH(如果 make.exe 最有可能在文件夹“bin”中,并且您有 msys,则它是 \msys\bin) 编译、运行、调试等很高兴。
回答by Hyman Offington
Just go to Settings>>Compiler and Debugger, then click the Linker Settings tab and go over to the "Other linker options" edit control and paste: "-static-libgcc -static-libstdc++" to it, there is no compiler flag option in the Compiler Flags options for Code::Blocks so that's the way to solve that problem, I came here looking for a solution also and the one guy that posted about "-static-libgcc -static-libstdc++" gave the right idea, and I sort of figured the rest out by accident but it worked, the file is clickable now from outside Code::Blocks, works right from the desktop.
只需转到设置>>编译器和调试器,然后单击链接器设置选项卡并转到“其他链接器选项”编辑控件并粘贴:“-static-libgcc -static-libstdc++”,没有编译器标志选项在 Code::Blocks 的 Compiler Flags 选项中,这是解决该问题的方法,我来到这里也是为了寻找解决方案,并且发布有关“-static-libgcc -static-libstdc++”的人给出了正确的想法,并且我有点意外地想通了其余部分,但它起作用了,该文件现在可以从 Code::Blocks 外部单击,直接从桌面运行。
回答by yossi
Can't you put it in system32 or something like you do with others dll files, so that every program you try to run won't have that problem on your machine?
你不能把它放在 system32 或像你对其他 dll 文件所做的那样,这样你尝试运行的每个程序都不会在你的机器上出现这个问题吗?
I just need the path where to put it.
我只需要放置它的路径。
It is kinda annoying to put it in the directory every time I run a program I just built...
每次运行我刚构建的程序时都把它放在目录中有点烦人......
Edit: I found the solution:
编辑:我找到了解决方案:
Extract libgcc_s_dw2-1.dll to a location on your computer. We recommend you to unzip it to the directory of the program that is requesting libgcc_s_dw2-1.dll.
If that doesn't work, you will have to extract libgcc_s_dw2-1.dll to your system directory. By default, this is:
- C:\Windows\System (Windows 95/98/Me)
- C:\WINNT\System32 (Windows NT/2000)
- C:\Windows\System32 (Windows XP, Vista, 7)
If you use a 64-bit version of Windows, you should also place libgcc_s_dw2-1.dll in C:\Windows\SysWOW64\
Make sure overwrite any existing files (but make a backup copy of the original file). Reboot your computer.
If the problem still occurs, try the following:
- Open Windows Start menu and select "Run...".
- Type CMD and press Enter (or if you use Windows ME, type COMMAND)).
- Type regsvr32 libgcc_s_dw2-1.dll and press Enter.
将 libgcc_s_dw2-1.dll 解压缩到您计算机上的某个位置。我们建议您将其解压到请求 libgcc_s_dw2-1.dll 的程序所在的目录中。
如果这不起作用,您必须将 libgcc_s_dw2-1.dll 解压缩到您的系统目录。默认情况下,这是:
- C:\Windows\System (Windows 95/98/Me)
- C:\WINNT\System32 (Windows NT/2000)
- C:\Windows\System32(Windows XP、Vista、7)
如果您使用 64 位版本的 Windows,您还应该将 libgcc_s_dw2-1.dll 放在 C:\Windows\SysWOW64\
确保覆盖任何现有文件(但制作原始文件的备份副本)。重新启动计算机。
如果问题仍然存在,请尝试以下操作:
- 打开 Windows 开始菜单并选择“运行...”。
- 键入 CMD 并按 Enter(或者,如果您使用的是 Windows ME,请键入 COMMAND))。
- 键入 regsvr32 libgcc_s_dw2-1.dll 并按 Enter。
回答by yossi
Go to the MinGW http sourceforge.net tree. Under Home/MinGW/Base/gcc/Version4(or whatever version use are using)/gcc-4(version)/ you'll find a file like gcc-core-4.8.1-4-mingw32-dll.tar.lzma. Extract it and go into the bin folder where you'll find your libgcc_s_dw2-1.dll and other dll's. Copy and paste what you need into your bin directory.
转到 MinGW http sourceforge.net 树。在 Home/MinGW/Base/gcc/Version4(或正在使用的任何版本)/gcc-4(version)/ 下,你会找到一个像 gcc-core-4.8.1-4-mingw32-dll.tar.lzma 这样的文件. 解压并进入 bin 文件夹,您将在其中找到 libgcc_s_dw2-1.dll 和其他 dll。将您需要的内容复制并粘贴到您的 bin 目录中。