Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Linking to Allegro 4.4.2

Credits go to Edgar Reynaldo and Peter Hull for helping out!
This thread is locked; no one can reply to it. rss feed Print
Linking to Allegro 4.4.2
Christer Sandberg
Member #16,831
March 2018

I want to build an application that depends on Allegro 4.4.2. This works fine on Linux. On Windows I followed the instructions for MinGW32 and Cmake, and Allegro built and installed fine (using the default options to CMake). I have verified that liballeg.a is present in MinGW\lib and allegro.h as well as the directory allegro is present in MinGW\include.
I used the build command suggested in allegro\docs\build\mingw32.html:
gcc x.c -Wl,--subsystem,windows -O2 -Wall -o x.exe -lalleg
to compile and link the following code:

#SelectExpand
1#include <allegro.h> 2int main(void) { 3 allegro_init(); 4 return 0; 5} 6END_OF_MAIN()

and then get:

c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../liballeg.a(wsystem.c.obj): In fun
ction `sys_directx_get_desktop_resolution':
C:/allegro/allegro-4.4.2/allegro/src/win/wsystem.c:434: undefined reference to `
GetDeviceCaps@8'
C:/allegro/allegro-4.4.2/allegro/src/win/wsystem.c:435: undefined reference to `
GetDeviceCaps@8'

(more undefined refs follows)
gcc version is 4.5.0
Any advice?

Peter Hull
Member #1,136
March 2001

Try adding -lgdi32 to the compiler command line

Christer Sandberg
Member #16,831
March 2018

That made difference, but there are still lots of unsolved references.

C:/allegro/allegro-4.4.2/allegro/src/win/wkeybd.c:679: undefined reference to `I
ID_IDirectInputA'
C:/allegro/allegro-4.4.2/allegro/src/win/wkeybd.c:679: undefined reference to `C
LSID_DirectInput'
C:/allegro/allegro-4.4.2/allegro/src/win/wkeybd.c:679: undefined reference to `C
oCreateInstance@20'

etc.
Can it be something wrong with the Direct X library? I used the dx80_mgw.zip package from allegro.cc, unpacked and replaced files in bin and lib.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You're linking to the static library, which means you also need to link to all the dependencies.

I think this is the full list of libraries you need to link to besides liballeg.a :

-static -lalleggl -ljpgalleg -lloadpng -llogg -lalleg-debug-static -lvorbis -lvorbisenc -lvorbisfile -logg -lpng16 -lzlibstatic -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound -static-libstdc++ -static-libgcc

Christer Sandberg
Member #16,831
March 2018

What makes you believe that I'm linking statically? There is no library liballeg-static.a only liballeg.a, so at least according to the docs it has been built dynamic. That is also what should happen if using default settings to CMake, again according to docs. On the other hand liballeg.a is surprisingly big (4.5M) to be for dynamic linking. So maybe you are right. I tested to compile again but without

-lloadpng
-llogg
-lalleg-debug-static
-lvorbis
-lvorbisenc
-lvorbisfile
-logg
-lpng16
-lzlibstatic
-lstatic-libstdc++

since they are not present on my system, and it worked. Now I also tried to build a copy of extrans.c using the same options to gcc as above which did not work:
<code>x.o:extrans.c:(.text+0xd1): undefined reference to `_imp__rgb_map'
x.o:extrans.c:(.text+0x1fb): undefined reference to _imp__color_map'
etc
But all the allegro examples were builds without problem when running through make, so it should be possible to re-do that.
Is there a way to tell CMake to generate makefiles to force make to show the actual commands that are issued instead of the message that it was successful?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Christer Sandberg
Member #16,831
March 2018

OK, thanks! (didn't test -DALLEGRO_STATICLINK before because I still trusted the docs' statement about library naming).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

ryafar said:

Is there a way to tell CMake to generate makefiles to force make to show the actual commands that are issued instead of the message that it was successful?

You can set the CMAKE_VERBOSE_MAKEFILE option to 'On', and it will give you much more information. Probably too much.

Go to: