Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » How to fix error -lstdc++ ?

This thread is locked; no one can reply to it. rss feed Print
How to fix error -lstdc++ ?
jomi77
Member #14,799
December 2012

Hello all.

I'm having a problem that I can't seem to figure out. Whenever I build and run the test program to check if Allegro 5 works, I get this error:

ld.exe cannot find -lstdc++

This is the code:

#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>

int main(void)
{
ALLEGRO_DISPLAY *display = NULL;

if(!al_init())
{
al_show_native_message_box(NULL, NULL, NULL, "Failed To Initialize", NULL, NULL);
return -1;
}

display = al_create_display(640, 480);

if(!display)
{
al_show_native_message_box(NULL, NULL, NULL, "Failed To Display", NULL, NULL);
return -1;
}

al_destroy_display(display);
return 0;
}

I've watched about 5 different video tutorial on youtube on how to link all the bin, include and lib files so I'm really confused as to why I'm getting this error. I'm using allegro-5.0.8-mingw-4.6.2 and CodeBlocks 10.5

If anyone can help I would appreciate it a ton.
Thanks and Happy Holidays

Arthur Kalliokoski
Second in Command
February 2005
avatar

Thing to try that might help:

As root (sudo) say "ldconfig"

Or "set | grep LD_LIBRARY_PATH" and check that the directory the Allegro libs are in is listed.

They all watch too much MSNBC... they get ideas.

jomi77
Member #14,799
December 2012

Hello Arthur, could you explain how exactly to do that? I am a complete noob and didn't even know about Allegro a week ago.

Also, is the order in which I include the files in CodeBlocks really that important? I just copy and pasted the files like I saw in the tutorials I watched and it seemed to work for them. Last question what is the difference between dynamic linking and static linking?

Sorry for all the questions.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I just now saw the ".exe" at the end of ld, and what I posted above was for linux. As for windows, I guess you're using Mingw? Probably wrong environment variables again.

Try typing these lines in from a command prompt and start Codeblocks from that.

set MINGDIR=c:\mingw
set C_INCLUDE_PATH=<whereever you've unpacked the Allegro files\include>
set path=%path%;c:\mingw\bin

That's not really how it should be done, but I don't remember all the rigamarole needed in control panel to set them permanently.

They all watch too much MSNBC... they get ideas.

LennyLen
Member #5,313
December 2004
avatar

Can you build a simple "Hello World" application? My guess is that you're missing part of the MinGW package.

jomi77
Member #14,799
December 2012

LennyLen I just tried to make a Hello World app and got the same error. I think that is the problem, but how can I fix it? I could make a Hello World app before just fine.

LennyLen
Member #5,313
December 2004
avatar

You could just try removing the current MinGW installation and reinstall it from scratch.

Arthur Kalliokoski
Second in Command
February 2005
avatar

LennyLen said:

You could just try removing the current MinGW installation and reinstall it from scratch.

Huh. Windows.

DDYiC.gif

They all watch too much MSNBC... they get ideas.

jomi77
Member #14,799
December 2012

The only MINGW I have is what I downloaded with CodeBlocks. I guess I'll just try again later and uninstall everything and start from scratch again.

Thanks.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

What are you guys talking about? WTF...???

- Dont pass -lstdc+++ to the compiler. It is not necessary. MinGW automatically links to the standard c++ library for you when you use g++ or mingw32-g++. If you want to link to the c and c++ libraries statically so you don't have to drag around those dlls, then use something like :
--static-libstdc++
--static-libgcc

LennyLen
Member #5,313
December 2004
avatar

Dont pass -lstdc+++ to the compiler. It is not necessary. MinGW automatically links to the standard c++ library for you when you use g++ or mingw32-g++. If you want to link to the c and c++ libraries statically so you don't have to drag around those dlls, then use something like :

He said he was following A5 tutorials, and none of them link directly to libstc++, so it's fairly safe to assume that jomi77 isn't doing so either. Hence why I'm inclined to think that his MinGW installation has been corrupted somehow.

jomi77
Member #14,799
December 2012

Ok so I unistalled CodeBlocks and downloaded the newest version. I can now run a Hello World program succesfully. I linked the libraries but now I get these errors:

line 8 undefined reference to al_install_system
line 10 undefined reference to al_show_native_message_box
line 14 undefined reference to al_create_display
line 18 undefined reference to al_show_native_message_box
line 22 undefined reference to al_destroy_display

and two warnings:

line 10 warning: passing NULL to non-pointer argument 6 of int al_show_native_message_box(ALLEGRO_DISPLAY*, const_char*, const_char*, const_char*, )

line 18 warning: passing NULL to non-pointer argument 6 of int al_show_native_message_box(ALLEGRO_DISPLAY*, const_char*, const_char*, const_char*, )

Any idea as to what the problem might be this time?

Arthur Kalliokoski
Second in Command
February 2005
avatar

The undefined references come failure to link the libraries and the warnings are from using native message box incorrectly.

You really have to put a little more effort into this yourself.

They all watch too much MSNBC... they get ideas.

billyquith
Member #13,534
September 2011

libc++ is the new C++11 library for LLVM clang. libstdc++ is the GCC version. You cannot mix these.

libc++: http://libcxx.llvm.org

Go to: