Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Code::Blocks Linker Problem

This thread is locked; no one can reply to it. rss feed Print
Code::Blocks Linker Problem
_Xero_
Member #12,472
December 2010

Hello everyone,
im new to Allegro and have a question concerning setting up my IDE.
After fallowing the introductions in this thread

http://www.allegro.cc/forums/thread/605784

i tried to compile this code

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3 4int main(int argc, char **argv) 5{ 6 ALLEGRO_DISPLAY *display = NULL; 7 8 if(!al_init()) { 9 fprintf(stderr, "failed to initialize allegro!\n"); 10 return -1; 11 } 12 13 display = al_create_display(640, 480); 14 if(!display) { 15 fprintf(stderr, "failed to create display!\n"); 16 return -1; 17 } 18 19 al_clear_to_color(al_map_rgb(0,0,0)); 20 21 al_flip_display(); 22 23 al_rest(10.0); 24 25 al_destroy_display(display); 26 27 return 0; 28}

and got these errors

Compiling: main.cpp
Linking console executable: bin\Debug\Allegro_Test.exe
obj\Debug\main.o: In function `main':
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:8: undefined reference to `al_install_system'
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:13: undefined reference to `al_create_display'
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:19: undefined reference to `al_map_rgb'
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:19: undefined reference to `al_clear_to_color'
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:21: undefined reference to `al_flip_display'
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:23: undefined reference to `al_rest'
E:/C++/Projekte/Allegro_Test/Allegro_Test/main.cpp:25: undefined reference to `al_destroy_display'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 5 seconds)
7 errors, 0 warnings

In this thread
http://www.allegro.cc/forums/thread/605768
Matthew Leverton said that liballegro-5.0.0-RC2-md.a (liballegro-5.0.0-RC4-md.a in my case) needs to be linked.
Isn't that already done by adding the allegro\lib path to the Linker Directories?
If not how do i link it?

Hedgie
Member #12,494
January 2011

Getting Allegro to play nice or any library for that matter always seems to make me stumble too. I searched and read all kind of material over the internet to try and get RC4 to work but just can't seem to figure out what I'm doing wrong. I have read through the various threads here and none of them seem to help. Just a note I've pretty much done the same as Xero and am still having some of the same issues.

Matthew Leverton
Supreme Loser
January 1999
avatar

_Xero_ said:

Isn't that already done by adding the allegro\lib path to the Linker Directories?

No. That just tells the compiler where to look for libraries that you explicitly specify later.

Quote:

If not how do i link it?

Add it to the list of libraries to link. Your IDE will have that option somewhere.

_Xero_
Member #12,472
December 2010

Thanks Matthew,
I found the option under Project -> Build Options -> Linker Settings

@Hedgie: If you use Code::Blocks

Go to Settings / Compiler and Debugger / Global compiler settings
Go to Search Directories tab
Under Compiler, add c:\allegro\include
Under Linker, add c:\allegro\lib
Go to Toolchain executables tabs
Under Additional Paths, add c:\allegro\bin

and then link the liballegro-5.0.0-RC4-md.a as i said above

good luck^^

Hedgie
Member #12,494
January 2011

Okay so part of the problem is figured out if I use the library file "liballegro-5.0.0-RC4-md.a" I can get the first allegro 5 tutorial(The display one) to compile just fine. But what I'm really going after is trying to use "liballegro-5.0.0-RC4-monolith-static-mt.a" and "liballegro-5.0.0-RC4-monolith-static-mt-debug.a" and when attempt to compile using one of the two file Codeblocks seems to treat the file differently. I even make sure to define ALLEGRO_STATICLINK before all my headers and get various errors.

This particular one is straight out of my build log.
to `glGetString@4'
d:/Libraries/build/allegro/src/allegro-5.0.x/allegro-5.0.x/src/win/wgl_disp.c:1044: undefined reference to `glGetString@4'
Process terminated with status 1 (0 minutes, 1 seconds)
50 errors, 0 warnings

The other 50 errors Pastebin

Note: The libraries aren't located on my D: drive they're in my J: drive making me wonder if there is something wrong with the library itself.

Fworg64
Member #12,077
June 2010

Please help, Same problem. I'd be willing to switch IDE's if anyone knows one that plays nice with allegro other then Dev C++.

I know what I'm doing, I'm just not very good at it. -Austin Oltmanns

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

When linking statically, I think there are several other libraries that you have to link to as well. For instance, it looks like you're not linking to the OpenGL library according to your undefined reference to glGetString@4. It looks like there are other libraries you have to link to as well according to your log on pastebin.

Can someone post a list of the extra libraries that you need to link to when you're linking with Allegro5 statically please? I googled for them, but came up with nothing in the manual or documentation or forums.

Matthew Leverton
Supreme Loser
January 1999
avatar

Something like -lglu32 -lglut32 -lopengl32.

Fworg64 said:

I'd be willing to switch IDE's if anyone knows one that plays nice with allegro other then Dev C++.

This has nothing to do with Dev-C++, but Code::Blocks is generally preferred over it.

Hedgie
Member #12,494
January 2011

Another note to put in here is I was using TDM-mingw and while everything has compile just fine, it seems that Allegro 5 and TDM-mingw is incompatible in some way at the moment. I'm getting the official Mingw right now but if this isn't some kind of mistake on my end maybe this needs to be documented?

Okay nevermind, I'm getting the same error with mingw as with TDG-mingw. The program compiles just fine but when I go to run it I get a window with this message "The procedure entry point __gxx_personality_v0 could not be located on the dynamic link library libstdc++-6.dll" I really have no clue what this message is trying to explain at all. This is the first of this kind of error I've ever seen. Any advice?

Fworg64
Member #12,077
June 2010

@Matthew Leverton
My bad I phrased that wrong :P , I do use code::blocks but I remember Dev C++ had some nice integrated library installing feature. I have the exact same problem as Xero

I know what I'm doing, I'm just not very good at it. -Austin Oltmanns

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Fworg64
Member #12,077
June 2010

Ok i lied my problems different, it was the same for a while though nut now its this

#SelectExpand
1#define ALLEGRO_STATICLINK 1 2#include <allegro5/allegro.h> 3 4int main(void) 5{ 6 al_init(); 7 8 ALLEGRO_DISPLAY *display = al_create_display(640, 480); 9 10 al_clear_to_color(al_map_rgb(0, 150, 0)); 11 12 al_flip_display(); 13 14 al_rest(5); 15 16 return 0; 17} 18END_OF_MAIN()

and the errors i get are

#SelectExpand
1main.cpp|8|warning: unused variable 'display'| 2C:\C++ projects\Alleg5test\main.cpp|18|error: expected constructor, destructor, or type conversion at end of input|

I can guess the first one is just because i didn't say display anywhere else in main but I'm at a loss for that last one, I've tried with and without a semicolon but to no avail.

I know what I'm doing, I'm just not very good at it. -Austin Oltmanns

Matthew Leverton
Supreme Loser
January 1999
avatar

Don't use END_OF_MAIN with Allegro 5.

Fworg64
Member #12,077
June 2010

Thank you kind sir,

I know what I'm doing, I'm just not very good at it. -Austin Oltmanns

AMCerasoli
Member #11,955
May 2010
avatar

Can someone post a list of the extra libraries that you need to link to when you're linking with Allegro5 statically please?

We're more or less on the same problem... See this threat... http://www.allegro.cc/forums/thread/606040/0

Michał Cichoń Once says... Here http://www.allegro.cc/forums/thread/605692

Assume you're using MinGW GCC 4.5.0. To compile Allegro as static library with static run-time libraries use following switches:

Switches for source files:
-s -DALLEGRO_SRC -DALLEGRO_STATICLINK -DALLEGRO_LIB_BUILD
Switches for linker:
-lgcc_eh -static-libgcc -static-libstdc++

Switches for executable:
Switches for source files:
-s -DALLEGRO_STATICLINK
Switches for linker:

-lgcc_eh -static-libgcc -static-libstdc++

Libraries:
Allegro and add-ons (list all your application, you may list all they will be ignored if not used):
allegro-5.1.0-static-mt
allegro_audio-5.1.0-static-mt
...

Direct dependencies (libraries used by Allegro):

libFLAC-1.2.1-static-mt
libvorbisfile-1.2.3-static-mt
libvorbis-1.2.3-static-mt
libogg-1.1.4-static-mt
dumb-0.9.3-static-mt
zlib-1.2.5-static-mt
physfs-2.0.0-static-mt
freetype-2.4.2-static-mt

Indirect dependencies (DLL's availabe in system):

gdiplus
uuid
kernel32
winmm
psapi
opengl32
glu32
user32
comdlg32
gdi32
shell32
ole32
advapi32
ws2_32

If someone knows how to use this information please post it... ;D I'm using Code Block...

I manually linked to the Indirect Dependencies, which are all in the System32 folder... But I couldn't find "uuid.dll" and I still getting errors... I'm using the pre-build static binaries...

I did this...

http://www.cerebrospain.com/find5.gif

PS: You must link manually all those libraries if you want to compile statically...

Go to: