Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Sorry stupid question I'm sure...

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Sorry stupid question I'm sure...
StanEd
Member #16,038
August 2015

Hi guys,

I've been away from allegro for a while; especially in Windows but I now need to setup a windows environment for a specific project.

I followed the instructions here: https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5

Which have been great; but I'm stuck on linking. I'd prefer static, but I really don't mind if dynamic is easier.

I've tried this several ways:

Attempt 1:
So the guidance says:

Quote:

When linking statically there are many more libraries that you need to link to.

File:CBLinkerSettings2.png

Here is the full list of libraries :

-lallegro_monolith-debug-static
-ljpeg
-ldumb
-lFLAC
-lfreetype
-lvorbisfile
-lvorbis
-logg
-lphysfs
-lpng16
-lzlibstatic
-ldsound
-lgdiplus
-luuid
-lkernel32
-lwinmm
-lpsapi
-lopengl32
-lglu32
-luser32
-lcomdlg32
-lgdi32
-lshell32
-lole32
-ladvapi32
-lws2_32
-lshlwapi
-static-libstdc++
-static-libgcc

So, I've made sure the allegro/lib folder is in the linker search directory and in codeblocks I do Project->Build Options->Linker settings then in the Other Linker options I paste the above.

But on compilation it says it cannot find any of them.

Addendum I have also added these to the Settings->Compiler linker settings.

Trial 2:

in the linked libraries section I have added 'liballegro-5.0.10-monolith-static-mt.a' which I understand to be enough to compile the following:

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

But this gives undefined reference errors for all the allegro functions. I am guessing I am missing a linked library, but to be honest I can't work out which ones I would need to include.

I guess that the assumption the the monolith is everything roled in to one is not correct?

Can anyone point me to what I need to include or why the -l... options from the guidance wouldn't work?

Thank you,

Stan

Further test

I have now added a link to all the .a files that are labelled as static and the it still doesn't compiler (same reference errors).

Thanks again,

Stan

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Sorry, it looks like the wiki lost some files. I still have the originals and I'll re-upload them.

Don't change your global compiler settings unless you really mean to. It's much better to use per-project settings.

First, check that you set the correct linker directory :
{"name":"611134","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/476c05bc16c80e249a8d01261702fef2.png","w":744,"h":424,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/476c05bc16c80e249a8d01261702fef2"}611134

Then, if you're linking statically, you need to define ALLEGRO_STATICLINK in all files that include allegro.

Honestly, linking dynamically is easier. It all depends on whether you want one file or many to distribute. If you link to the allegro monolith dynamically, then your executable will depend on all the dlls allegro needs.
{"name":"611135","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/47ffc8b8d42a18846a1974920e4e0ff0.png","w":738,"h":424,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/7\/47ffc8b8d42a18846a1974920e4e0ff0"}611135

If you still have errors, please post them.

StanEd
Member #16,038
August 2015

Hi Edgar,

Thanks, for replying and with the pictures.

Don't change your global compiler settings unless you really mean to. It's much better to use per-project settings.

Apologies I was unclear; I have set these on the project level; but while trying to get things working I also set them in the Global compiler settings. Mine are full pathed (c:\allegro\lib and c:\allegro\include) in both the project and global level.

Edgar Reynaldo said:

Honestly, linking dynamically is easier. It all depends on whether you want one file or many to distribute. If you link to the allegro monolith dynamically, then your executable will depend on all the dlls allegro needs.

Ah, I thought Static was the preferred method, the aim is to make a few small tools for a larger project so I don't mind either way.

Even setting the linkers as per the pictures (static or dynamic) I still get:

ld.exe cannot find -lallegro_monolith-debug.dll

I'm a bit vague on how the linker name relates to the actual filename. For example, I have these files:

  • liballegro-5.0.10-monolith-md-debug.a

  • liballegro-5.0.10-monolith-mt-debug.a

I did open these in notepad++ and had a look through but I couldn't identify a library name? Does the filename relate to the linker name? (I took the mingw 4.7 binaries from https://www.allegro.cc/files/) so it's allegro 5.0.10, but I'm not sure if I need a different linker name?

Thanks again,

Stan

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

StanEd
Member #16,038
August 2015

Hi Edgar,

Thanks for updating the images :D.

I did think it was related to the filenames; so it's odd that mine is still saying it can't find them.

I wonder if I've messed something else up in setup, so I think over the weekend I will start again from scratch and see if I can get better results.

Thank you for your help and patience.

Stan

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

StanEd
Member #16,038
August 2015

Hi Edgar,

Just thought I'd let you know that I started from scratch again today, and this time found the latest binaries at: https://github.com/liballeg/allegro5/releases rather than with the 5.0.* binaries here: https://www.allegro.cc/files/; and I managed to get it working fine. No idea what was wrong in my previous attempt but got it working so I'm happy with that :).

Thank you ever so much for your help.

Btw, I went with Dynamic in the end ;)

Stan

Go to: