[c++] 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 with 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?

This question is related to c++ windows mingw

The answer is


Add path to that dll into PATH environment variable.


See also. It solved my problem.

By the way, is it definitely compiler flag? Maybe linker is the more suitable term here?


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.

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

codeblocks compiler settings


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.

Eclipse properties screenshot

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.


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 :)


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


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.


Find that dll on your PC, and copy it into the same directory your executable is in.


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/


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.


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.


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.


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.


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to mingw

MINGW64 "make build" error: "bash: make: command not found" How to install MinGW-w64 and MSYS2? printf, wprintf, %s, %S, %ls, char* and wchar*: Errors not announced by a compiler warning? mingw-w64 threads: posix vs win32 Serial Port (RS -232) Connection in C++ What is difference between sjlj vs dwarf vs seh? Unable to specify the compiler with CMake to_string is not a member of std, says g++ (mingw) How to compile makefile using MinGW? Getting started with OpenCV 2.4 and MinGW on Windows 7