32

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

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.

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 post hardmath said to add -static-libgcc to 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.

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?

Community
  • 1
  • 1
Greg Treleaven
  • 8,124
  • 7
  • 30
  • 30
  • If the program is C++ then the error message could indicate that you have used something from the C++ standard library. The other linker option that was suggested is `-static-libstdc++`. Check that you've added that option as well. – hardmath Feb 13 '11 at 19:21
  • @hardmath: I've used . I think that's from C++ standard library. I was using `-static-libstdc++` when I was trying it, but the solution was actually just `-static` as @rubenvb said below. Thanks for taking time to help me. – Greg Treleaven Feb 13 '11 at 19:25
  • How do you add the linker option `-static-libgcc` in a codeblocks project? – FreelanceConsultant Aug 20 '15 at 20:13

1 Answers1

53

The link commandline argument -static-libgcc should work. Another variant you could try is 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.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • 3
    Using `-static` worked! Thanks a lot! :) – Greg Treleaven Feb 13 '11 at 19:20
  • 6
    Note that using `-static` will break throwing exceptions across DLL boundaries. – rubenvb Sep 26 '11 at 08:59
  • Also note that a dw2 built gcc will have problems with foreign exceptions (see for an explanation [TDM's info page](http://tdm-gcc.tdragon.net/start)) – rubenvb May 10 '12 at 19:49
  • Placing the DLLs alongside your executable works on a technical level, but could potentially cause disastrous licensing issues as the GPL expection clause applies to static linking and not dynamic linking as bizarre as that sounds. See: http://gcc.gnu.org/ml/gcc/2004-06/msg01123.html Failure to provide source to the dll could (possibly) put you in non-compliance with the license if you dynamically link. – Lisa Jul 28 '12 at 03:34
  • 4
    @user286101 that is untrue, please read the section `I use a proprietary compiler toolchain without any parts of GCC to compile my program, and link it with libstdc++.` on the [official faq](http://www.gnu.org/licenses/gcc-exception-faq.html) – rubenvb Jul 28 '12 at 11:17
  • 2
    Happened to me with libgcc_s_sjlj-1.dll - also -static-libgcc -static-libstdc++ solved this. – Xavi Montero Aug 20 '14 at 22:43
  • How do you add these linker options in a codeblocks project? – FreelanceConsultant Aug 20 '15 at 20:12
  • @XaviMontero I added `-static-libstdc++` to the other options of "Compiler Settings" on codeblocks, but get the error: "unrecognised command line option" – FreelanceConsultant Aug 20 '15 at 20:15
  • Don't know how to setup the options in `Code::Blocks`. I tried MinGW in the bash shell of an Ubuntu. But pretty sure the IDE supports passing options to the compiler. – Xavi Montero Aug 20 '15 at 23:12
  • @Xavi Have you tried looking at [the Code::Blocks documentation describing the build options](http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Modifying_build_options)? – rubenvb Aug 21 '15 at 07:32
  • I had not that need. I was answering @user3728501 because he addressed to me with the @ sign, but I don't use Code::Blocks at all. It is fine for me to compile from the shell. – Xavi Montero Aug 21 '15 at 17:11
  • I couldn't find it in the codeblocks doc. I don't think they are written particularly clearly. – FreelanceConsultant Aug 21 '15 at 20:32
  • -static did the trick for me; -static-libgcc did not work. – vvvv4d Oct 13 '21 at 20:54