69

I have been working on a project (a game to be specific) and I feel that I should start over with different libraries. So when doing this I reinstalled Code::Blocks and setup my new libraries and includes.

But as of now Im having a problem starting u[ my new project to test if all of the includes work. This problem is: libstdc++-6.dll was not found. At first i wondered if I could just find this file online, but its nowhere to be found(or at least the many places I have searched...) Soon after, I tried loading up my old project, and the same problem happened again(wierd... ._.) I was thinking its maybe my compiler, so I used my older compiler and it did the same thing! At this moment I held the problem off for tomorrow(which is today)

So my question is: If anyone else had this problem, how would you solve it?

Im using Code::Blocks with MinGW as the compiler on Windows Vista 32 bit.

*****EDIT*****

Here are the Build options in my project. Note that these are the settings in the Project, not the global compiler:

In (project name)->Compiler settings->Otehr options:

(I use // to seperate the commands)

-mthreads//
-fmessage-length=0//
-fexceptions//
-fident//

In (project name)->Compiler settings->#define:

WIN32//
_WINDOWS//

In (project name)->Linker settings->Other linker options:

-static-libstdc++//
-static-libgcc//
-Wl,--enable-auto-image-base//
-Wl,--add-stdcall-alias//
-Wl,--enable-auto-import//

In linker->link libraries i have various links to files with a .a extension, these files include Bullet PHysics, Ogre3D, and SFML

In the search directories i have links to the MinGW/bin, and the MinGW/lib directories, along with other links to different libraries.

My Compiler is MinGW, a GNU GCC compiler for windows 32 bit. and the IDE is Codeblocks. Also note that in Debug and Release settings on the project, there is nothing.

Most of these setings are also pieces that i got from the Ogre3D Application setup tutorial if that is of any help.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Molmasepic
  • 1,015
  • 2
  • 13
  • 18
  • Hey, I just removed the Ogre3D settings, and the program is working without any errors. Im thinking its something in the commands that I used that are triggering that dll error._. – Molmasepic Jun 21 '11 at 02:51
  • Hey again, I just started readding files back one by one, and i found out that the wrapper [btOgre](http://www.ogre3d.org/forums/viewtopic.php?f=5&t=46856) Is the cause of this dll error. My problem is that this is required to use Bullet Physics with ogre. Im going to try and find a way to use this correctly. – Molmasepic Jun 21 '11 at 03:23
  • Hey I decided to use OgreBullet instead of btOgre. I built it myself in codeBlocks, and it went perfectly. Thanks for the support and sorry for all the unneeded trouble. :) – Molmasepic Jun 21 '11 at 04:20
  • http://code.google.com/p/wtfu/downloads/detail?name=libstdc%2B%2B-6.dll&can=2&q= – appas Nov 26 '11 at 00:18

15 Answers15

131

If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I've found this approach the quickest and cleanest solution to creating Windows binaries.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • Its the same problem as said in the question: `libstdc++-6 not found`...you add those to the linker options right? also does it make a difference when the compiler settings have the libs? or the project settings? – Molmasepic Jun 20 '11 at 23:43
  • 1
    @Molmasepic: Your original question was very vague. Is is this compile-time, link-time or run-time error? Who emits it? What was the last thing you were doing, and what commands did you use to build the project? – Kerrek SB Jun 20 '11 at 23:45
  • oh im so sorry, i forgot about that...Its in the run-time, so its a runtime error. again sorry about that...the compiling went well, but right when the application starts, thats when it gave said error. – Molmasepic Jun 21 '11 at 01:09
  • @Molmasepic: Can you post details about the compiler and the platform you're using, and the commands you used to build the project? – Kerrek SB Jun 21 '11 at 01:11
  • I try to use -static-libgcc and -static-libstdc++ on MinGW 4.7.1, but it says: `mingw32-g++.exe: error: unrecognized command line option '-static-libstdc++'` – topright gamedev Jan 08 '13 at 22:15
  • @toprightgamedev: Are you sure you're using `g++` and not `gcc`? Double-check your project settings perhaps... – Kerrek SB Jan 08 '13 at 22:36
  • ar.exe is used as static linker and mingw32-g++.exe as dynamic (default settings for "Code::Blocks 12.11 + MinGW 4.7.1" distributive) – topright gamedev Jan 08 '13 at 22:39
  • For compat with older Windows releases, I also needed to add `-fPIC` – tresf Mar 26 '19 at 18:02
  • 4
    For me, I used `g++ -static application.cpp` and it did the trick. I'm using MSYS2. – Inarus Lynx Jun 19 '21 at 18:51
  • @InarusLynx +1 especially because with `-static-libgcc -static-libstdc++` I was still dependent on `libwinpthread-1.dll`. `-static` removed that dependency as well. I found this useful to show what is being loaded: https://learn.microsoft.com/en-us/sysinternals/downloads/listdlls (sort of the Windows equivalent of LD_DEBUG=libs on linux) It shows that, even with the above `-static` most applications are, of course, still dependent on a ton of standard dlls in `C:\\Windows\System32`. But every machine should at least have those. – Oliver Schönrock Feb 24 '22 at 16:11
  • How do I add these options on Clion – Cyber Avater Apr 13 '22 at 09:54
  • It took me a WHOLE day until I found this answer, thank you so much!!!!!! – Tin Po Chan May 21 '22 at 13:52
18

As far as I know, this is the C++ Runtime Library. So it depends on the compiler you use to create your program (A new version will include some C++0x stuff, an older version will probably not for instance. It depends of the compiler and of its version).

If you use MinGW then you should use the libstdc++-6.dll found into the folder of this compiler. MinGW/bin folder should be the place to search for it on your computer.

If you copy this file in the same directory as your executable, it should be OK.

Valkea
  • 1,216
  • 1
  • 12
  • 26
  • Yeah thats the problem Im having right there. In my older project, after changing my compiler back to the older one, It worked fine. But if i were to make a new project under the same compiler, I get that error...This really doesnt make sense how it didnt need the file before, but now it does...Also I never had that file in the first place, and i found out that the compiler versions(old and new) are exactly the same, as if i just reinstalled it... – Molmasepic Jun 19 '11 at 19:26
  • 5
    By simple adding "-static" to the compile command, the problem has gone for me. – meolic Aug 04 '20 at 21:20
7

Simply removing libstdc++-6.dll.a \ libstdc++.dll.a from the mingw directory fixes this.

I tried using the flag -static-libstdc++ but this did not work for me. I found the solution in: http://ghc.haskell.org/trac/ghc/ticket/4468#

Tamir
  • 221
  • 2
  • 5
5

This error also occurred when I compiled with MinGW using gcc with the following options: -lstdc++ -lm, rather than g++

I did not notice these options, and added: -static-libgcc -static-libstdc++

I still got the error, and finally realized I was using gcc, and changed the compiler to g++ and removed -stdc++ and -lm, and everything linked fine.

(I was using LINK.c rather than LINK.cpp... use make -pn | less to see what everything does!)

I don't know why the previous author was using gcc with -stdc++. I don't see any reason not to use g++ which will link with stdc++ automatically... and as far as I know, provide other benefits (it is the c++ compiler after all).

nckturner
  • 1,266
  • 1
  • 15
  • 19
4

useful to windows users who use eclipse for c/c++ but run *.exe file and get an error: "missing libstdc++6.dll"

4 ways to solve it

  1. Eclipse ->"Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" -> "MinGW C++ Linker" -> "Misscellaneous" -> "Linker flags" (add '-static' to it)

  2. Add '{{the path where your MinGW was installed}}/bin' to current user environment variable - "Path" in Windows, then reboot eclipse, and finally recompile.

  3. Add '{{the path where your MinGW was installed}}/bin' to Windows environment variable - "Path", then reboot eclipse, and finally recompile.

  4. Copy the file "libstdc++-6.dll" to the path where the *.exe file is running, then rerun. (this is not a good way)

Note: the file "libstdc++-6.dll" is in the folder '{{the path where your MinGW was installed}}/bin'

3

I use Eclipse under Fedora 20 with MinGW for cross compile. Use these settings and the program won't ask for libstdc++-6.dll any more.

Project type - Cross GCC

Cross Settings

  • Prefix: x86_64-w64-mingw32-
  • Path: /usr/bin

Cross GCC Compiler

  • Command: gcc

  • All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3 -Wall -c -fmessage-length=0

  • Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include

Cross G++ Compiler

  • Command: g++

  • All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3 -Wall -c -fmessage-length=0

  • Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include

Cross G++ Linker

  • Command: g++ -static-libstdc++ -static-libgcc

  • All Options: -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/bin

  • Library search path (-L):

    /usr/x86_64-w64-mingw32/sys-root/mingw/lib

    /usr/x86_64-w64-mingw32/sys-root/mingw/bin

3

I just had this issue.. I just added the MinGW\bin directory to the path environment variable, and it solved the issue.

Pseudyx
  • 63
  • 6
1

I placed the libstdc++-6.dll file in the same folder where exe file is generated.

Rudraksha
  • 37
  • 4
  • 1
    It is also solved by adding "mingw-install-directory"/bin/ to your Path in your System environment variables – Dan Ortega Jul 30 '18 at 18:07
1

You only need to add your "mingw-install-directory"/bin/ to your Path in your System environment variables ... that's it !!

Dan Ortega
  • 1,679
  • 17
  • 13
0

I had same problem. i fixed it. i was using Codeblocks and i save my .cpp file on desktop instead of saving it in Codeblocks file where MinGW is located. So i copied all dll files from MinGW>>bin folder to where my .cpp file was saved.

Apollo
  • 1
0

You can also copy the dll files in the directory of your exe file

cemal54
  • 11
0

I had this problem too. I was compiling in command prompt and used the flag -static. My command before: "g++ test.cpp -o test.exe" and afterwards: "g++ test.cpp -o test.exe -static"

0

If you are using CMake, include the following line in your CMakeLists.txt file:

    add_link_options(-static -static-libgcc -static-libstdc++)

This will enable static linking for your project.

sbrajchuk
  • 48
  • 6
0

Just copy the LIBMPFR-4.DLL to the MinGW/bin/, then you can run the code directly.

I just solved the problem, which I think is a compiler bug.

user16217248
  • 3,119
  • 19
  • 19
  • 37
Stu Fish
  • 1
  • 1
-1

I had the same problem and I solved it by running the compiled exe as an administrator.

Amr
  • 574
  • 1
  • 11
  • 15