The program can't start because libgcc_s_dw2-1.dll is missing
I have created a simple program in C++ with Code::Blocks.
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 wit开发者_运维技巧h this message:
The program can't start because libgcc_s_dw2-1.dll is missing from your computer.
Try reinstalling the program to fix this problem.
So, what is the problem? What do I have to do to fix it?
I believe this is a MinGW/gcc compiler issue, rather than a Microsoft Visual Studio setup.
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.
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).
Updated:
Based on feedback from Greg Treleaven (see comments below), I'm adding links to:
[Screenshot of Code::Blocks "Project build options"]
[GNU gcc link options]
The latter discussion includes -static-libgcc
and -static-libstdc++
linker options.
In Eclipse, you will find it under the project properties > 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.
Code::Blocks: add '-static' in settings->compiler->Linker settings->Other linker options.
See also. It solved my problem.
By the way, is it definitely compiler
flag? Maybe linker
is the more suitable term here?
Find that dll on your PC, and copy it into the same directory your executable is in.
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.
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.
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 :)
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?
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.
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.
Add path to that dll into PATH environment variable.
In CodeBlocks you can go to Settings...Compiler... and choose either 1) the two items in the blue box or 2) the one item in the green box
If you are wondering where you can download the shared library (although this will not work on your client's devices unless you include the dll) here is the link: https://de.osdn.net/projects/mingw/downloads/72215/libgcc-9.2.0-1-mingw32-dll-1.tar.xz/
Including -static-libgcc on the compiling line, solves the issue
g++ my.cpp -o my.exe -static-libgcc
According to: @hardmath
You can also, create an alias on your profile [ .profile ] if you're on MSYS2 for example
alias g++="g++ -static-libgcc"
Now your GCC command goes thru too ;-)
Remeber to restart your Terminal
Add "-static" to other linker options solves this problem. I was just having the same issue after I tested this on another system, but not on my own, so even if you haven't noticed this on your development system, you should check that you have this set if you're statically linking.
Another note, copying the DLL into the same folder as the executable is not a solution as it defeats the idea of statically linking.
Another option is to use the TDM version of MinGW which solves this problem.
Update edit: this may not solve the problem for everyone. Another reason I recently discovered for this is when you use a library compiled by someone else, in my case it was SFML which was improperly compiled and so required a DLL that did not exist as it was compiled with a different version of MinGW than what I use. I use a dwarf build, this used another one, so I didn't have the DLL anywhere and of course, I didn't want it as it was a static build. The solution may be to find another build of the library, or build it yourself.
Step 1: Set the -static-libgcc
and -static-libstdc++
flags, or, set the -static
flag under settings -> compiler -> global compiler settings | Compiler settings | Compiler Flags
Step 2 (not stressed in the other answers): Clean your build before building and running. Without cleaning, you may think that you are rebuilding the project but you will end up with the same .exe. Cleaning will, amongst other things, delete the files in the bin
and obj
folder so that when you build, a fresh new set of files are created in bin
and obj
folder.
Working with msys2 I have obtained the same error trying to execute release version of my project in a debug environment. The solution for my problem is obvious: use executable with debug symbols.
精彩评论