The program can't start because libgcc_s_dw2-1.dll is missing
Asked Answered
L

17

189

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?

Lafave answered 15/1, 2011 at 23:17 Comment(0)
I
215

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 -static-libgcc -static-libstdc++

to your compiler and linker 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.

Icefall answered 16/1, 2011 at 0:38 Comment(18)
I have the same problem as @xRobot, and I couldn't find anywhere to add stuff to compiler flags, so I tried adding it to Other Options, then Linker Options, and the error message still occurred. Is anything wrong with what I'm doing?Wallsend
@Greg Treleaven: Just for clarity, you are building an executable with Code::Block, it works as expected inside the IDE but reports an error "can't start because libgcc_s_dw2-1.dll is missing" when you try to run it outside the IDE. You checked the compiler's bin directory, and yes, this DLL is in fact there. You are trying to fix the problem by doing a static linkage, which pulls in compiled code from a library so the DLL (runtime linkage) is not needed, but it isn't working. Two suggestions: Do a clean build (changing options may not trigger a rebuild), and try adding the PATH variable.Icefall
@hardmath: Still not working after doing a clean rebuild, so I guess I'll have to use one of the other ways to fix this. Thanks for helping.Wallsend
@Greg Treleaven: The reason to try adding the compiler's bin directory to your PATH is to show (if that makes things work) that the executable is still being built for runtime linkage of the standard libraries (DLLs). I'm thinking that the problem is that and we need to find (if you want to do static linkage of library code) where to put the compiler flags.Icefall
@Greg Treleaven: Okay! Please have a look at the links I added above about build options for Code::Blocks.Icefall
@hardmath: I tried adding MinGW/bin directory to the global directories like in the link. It didn't stop the error. Was this the correct way to add it?Wallsend
@Greg Treleaven: I don't think you need to specify a directory for the static linkage (although this is what you did for PATH to get runtime linkage). See the screenshot halfway down the page for adding the static linker options as Linker Settings/Other Linker Options here: synthedit.com/sdk3_docs/compiler_codeblocks.htmIcefall
@hardmath: I thought that I'd found why it wasn't working, because I had been adding -static-libgcc to the linker settings while the project name was selected, not when debug was selected, but adding it to debug still didn't work. =( And on my current project, I'm planning on distributing my program. Even by switching the new MinGW directory to the older one, the same error occurred.Wallsend
@Greg Treleaven: I'm going to suggest you open a new question, putting a link back to this one, explaining you got the runtime linkage to work but not the static linkage. A new question would give us more "elbow room" to post some sample project, etc. unhindered by the character limits of the comment box. What do you think?Icefall
This discussion continues (and is solved) here.Bernicebernie
How to add those flags? I am using CodeBlocks with Mingw. Any help is appreciated.Donnadonnamarie
@RogUE: Did you see the link (Updated in Answer) to a screenshot of the CodeBlocks project options settings?Icefall
Yes I did. But I can't figure it out how to do, it's a lot of information there. I can't understand it as I have only started to learn.Donnadonnamarie
Including -static-libgcc -static-libstdc++ on the compiling line, solved the issueHydnocarpate
The third one also necessary to include -static. So you have had three of them: -static -static-libgcc -static-libstdc++ on the compiling line.Chickenlivered
"you can avoid the problem by adding "-static-libgcc -static-libstdc++" to your compiler flags." But how to do this?Spandau
I am also using Code::Blocks and having exact the same problem.Spandau
@convert: Have a look at the self-answered Question How can build options be changed in Code::Blocks?Icefall
G
36

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.

Gemstone answered 22/12, 2011 at 8:52 Comment(2)
Is there a way to avoid adding the linker flag in each newly created project?Petrick
To the readers: Please note the options added in the image. This works. This helps as a reference: orfe.princeton.edu/help/article-296Basanite
B
16

Code::Blocks: add '-static' in settings->compiler->Linker settings->Other linker options.

Bethesde answered 20/1, 2013 at 17:10 Comment(4)
This worked perfectly for me regarding the "missing" dll per the title, it is so quick and easy, I'd recommend having a go at this one first.Sldney
Best solution !Anodic
This should be the accepted solution indeed! Quick and easy.Druse
Agree with previous coments, this solved exactly the same problem I had.Spandau
N
8

See also. It solved my problem.

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

Nympholepsy answered 24/11, 2011 at 13:21 Comment(1)
+1 for correct terminolgy! Yes, my "link" to gcc link options was an inkling of that (for the static libraries).Icefall
N
7

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

Nasya answered 15/1, 2011 at 23:21 Comment(2)
why does not this happen with visual studio ?Lafave
It also does, but with other dlls. Examples, if you lack msvcrt90.dll, your visual compiled project won't start (iut's usually installed system wide though)Ruel
V
6

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.

Vulnerary answered 7/10, 2011 at 23:8 Comment(0)
T
5

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.

Tiresias answered 23/6, 2013 at 14:25 Comment(0)
C
5

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.

Chef answered 24/2, 2015 at 22:3 Comment(0)
K
5

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

Kerrikerrie answered 24/6, 2015 at 21:14 Comment(0)
R
4

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.
Riebling answered 31/1, 2012 at 14:55 Comment(1)
Please don't post comments as answers here. That isn't how Stack Overflow works. You also won't get far using "u" instead of "you" and "cos" instead of "because". Chat speak is specifically disallowed here.Nadabas
I
3

Add path to that dll into PATH environment variable.

Ilise answered 15/1, 2011 at 23:24 Comment(2)
why does not this happen with visual studio ?Lafave
Probably because path to that dll is listed in VisualStudio's Tools-> Options->Projects and Solutions -> VC++ Directories -> Executable Files. Visual Studio looks here and in PATH environment variable when searching for paths to dlls.Ilise
V
3

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

Verbal answered 8/1, 2020 at 14:31 Comment(0)
M
3

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/

Merwin answered 9/6, 2020 at 17:58 Comment(1)
FINALLY! After decades of searching through a ridiculous number of ridiculously named MinGW download release files! What a save, thanks.Brabble
B
3

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.

Berber answered 14/5, 2021 at 20:13 Comment(0)
S
2

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.

Shelled answered 23/9, 2013 at 18:33 Comment(1)
Adding "-static" to linker and compiler options is defenetly the best solution. At least it worked for me.Spandau
H
2

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

Hydnocarpate answered 12/10, 2019 at 16:30 Comment(0)
C
0

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.

Conjunction answered 28/5, 2018 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.