Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Compiling Allegro 5 examples

This thread is locked; no one can reply to it. rss feed Print
Compiling Allegro 5 examples
wanton
Member #15,527
March 2014

I am attempting to compile the default, unmodified, Allegro 5 examples using MinGW. I have extracted the latest precompiled Allegro build into C:\allegro and am trying to compile an example using the following command:

gcc ex_winfull.c -o ex_winfull.exe -DPSAPI_VERSION=1 -DALLEGRO_STATICLINK -LC:\allegro\lib\ -IC:\allegro\include\ -lallegro-5.0.10-static-mt -lallegro_primitives-5.0.10-static-mt -lallegro_acodec-5.0.10-static-mt -lallegro_audio-5.0.10-static-mt -lallegro_color-5.0.10-static-mt -lallegro_dialog-5.0.10-static-mt -lallegro_font-5.0.10-static-mt -lallegro_image-5.0.10-static-mt -lallegro_memfile-5.0.10-static-mt -lallegro_physfs-5.0.10-static-mt -lallegro_ttf-5.0.10-static-mt -ldumb-0.9.3-static-mt -lFLAC-1.2.1-static-mt -lfreetype-2.4.8-static-mt -logg-1.2.1-static-mt -lopenal-1.14-static-mt -lvorbis-1.3.2-static-mt -lvorbisfile-1.3.2-static-mt -lmingw32 -lwinmm -lws2_32 -lopengl32 -lglu32 -lshlwapi -ld3d9 -ldxguid -lpsapi -lwinmm -lole32 -lcomdlg32 -lgdi32 -luser32 -mwindows -lkernel32

This is my output:

C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x948): undefined reference to `__cxa_guard_acquire'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x968): undefined reference to `__cxa_guard_release'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x979): undefined reference to `__cxa_guard_acquire'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x99f): undefined reference to `__cxa_guard_release'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x9d7): undefined reference to `__cxa_guard_abort'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x9ed): undefined reference to `__cxa_guard_abort'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.eh_frame+0x63): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Attempting to compile any other examples gives more errors, so I want to compile this simple example first.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

wanton
Member #15,527
March 2014

I have uninstalled, and installed MinGW 4.7.0 which is the latest, supported version of MinGW.

I then downloaded and extracted the Windows Binary for MinGW 4.7.0 from the official download page (https://www.allegro.cc/files/) into C:\allegro.

I then downloaded and extracted the examples from the same page.

I then run the command from the first post and receive the exact same error. I am sure that I am using MinGW 4.7.0 with Windows Binary for MinGW 4.7.0 which should be compatible.

What am I doing wrong and why is there no support for the latest MinGW?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

http://stackoverflow.com/questions/329059/what-is-gxx-personality-v0-for
http://stackoverflow.com/questions/6045809/problem-with-g-and-undefined-reference-to-gxx-personality-v0

I didn't notice you were linking to the mt versions. When you link to the mt versions you need to statically link the c standard library in as well, because that is how they were compiled.

So what you need to do is use the md versions and g++, or link statically to libstdc++ using --static-libstdc++.

edit

wanton said:

What am I doing wrong and why is there no support for the latest MinGW?

The latest MinGW compiles allegro just fine as far as I know. The person who provides the binaries probably just hasn't had time to implement the latest version of MinGW in his build system.

wanton
Member #15,527
March 2014

Still getting much of the same:

C:\allegro\examples>gcc ex_winfull.c -o ex_winfull.exe -DPSAPI_VERSION=1 -DALLEG
RO_STATICLINK -LC:\allegro\lib\ -IC:\allegro\include\ -lallegro-5.0.10-static-mt
-lallegro_primitives-5.0.10-static-mt -lallegro_acodec-5.0.10-static-mt -lalleg
ro_audio-5.0.10-static-mt -lallegro_color-5.0.10-static-mt -lallegro_dialog-5.0.
10-static-mt -lallegro_font-5.0.10-static-mt -lallegro_image-5.0.10-static-mt -l
allegro_memfile-5.0.10-static-mt -lallegro_physfs-5.0.10-static-mt -lallegro_ttf
-5.0.10-static-mt -ldumb-0.9.3-static-mt -lFLAC-1.2.1-static-mt -lfreetype-2.4.8
-static-mt -logg-1.2.1-static-mt -lopenal-1.14-static-mt -lvorbis-1.3.2-static-m
t -lvorbisfile-1.3.2-static-mt -lmingw32 -lwinmm -lws2_32 -lopengl32 -lglu32 -ls
hlwapi -ld3d9 -ldxguid -lpsapi -lwinmm -lole32 -lcomdlg32 -lgdi32 -luser32 -mwin
dows -lkernel32 -static-libstdc++
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x948): undefined reference to `__cxa_guard_acquire'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x968): undefined reference to `__cxa_guard_release'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x979): undefined reference to `__cxa_guard_acquire'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x99f): undefined reference to `__cxa_guard_release'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x9d7): undefined reference to `__cxa_guard_abort'
C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.o):d3d_display
_formats.cpp:(.text+0x9ed): undefined reference to `__cxa_guard_abort'
c:/mingw/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.0/../../../../i686-w64-mingw3
2/bin/ld.exe: C:\allegro\lib/liballegro-5.0.10-static-mt.a(d3d_display_formats.
o): bad reloc address 0x20 in section `.eh_frame'
c:/mingw/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.0/../../../../i686-w64-mingw3
2/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Also, I would rather not stoop to using C++ thanks.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

wanton
Member #15,527
March 2014

Using g++, it gives no compile errors or warnings.

g++ ex_winfull.c -o ex_winfull.exe -DPSAPI_VERSION=1 -DALLEGRO_STATICLINK -LC:\allegro\lib\ -IC:\allegro\include\ -lallegro-5.0.10-static-mt -lallegro_primitives-5.0.10-static-mt -lallegro_acodec-5.0.10-static-mt -lallegro_audio-5.0.10-static-mt -lallegro_color-5.0.10-static-mt -lallegro_dialog-5.0.10-static-mt -lallegro_font-5.0.10-static-mt -lallegro_image-5.0.10-static-mt -lallegro_memfile-5.0.10-static-mt -lallegro_physfs-5.0.10-static-mt -lallegro_ttf-5.0.10-static-mt -ldumb-0.9.3-static-mt -lFLAC-1.2.1-static-mt -lfreetype-2.4.8-static-mt -logg-1.2.1-static-mt -lopenal-1.14-static-mt -lvorbis-1.3.2-static-mt -lvorbisfile-1.3.2-static-mt -lmingw32 -lwinmm -lws2_32 -lopengl32 -lglu32 -lshlwapi -ld3d9 -ldxguid -lpsapi -lwinmm -lole32 -lcomdlg32 -lgdi32 -luser32 -mwindows -lkernel32 -static-libstdc++

However I can't run the compiled ex_winfull.exe binary. A window never shows up, and there is no task in task manager.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I'm guessing then that allegro was compiled with g++ or there is now c++ code in allegro. Yeah, there are now cpp source files for dsound and the primitives addon. So if you link to them then you need to link with g++.

And try running your compiled example from a console. It should say something or pop up some dialog if things fail. And you need to compile and link common.c to your program as well since it has some functions you're using.

You might have to check the processes tab to see if your program is still running or not. If it doesn't create a window it probably won't have a minimized icon.

wanton
Member #15,527
March 2014

I tried running from CMD, no output whatsoever. As I said, no process shows up in task manager either. I didn't think linking to common.c was necessary because line 3 of ex_winfull.c is:

#include "common.c"

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

wanton
Member #15,527
March 2014

So no one here knows how to compile the examples statically?

pkrcel
Member #14,001
February 2012

SO far seems to me you've done it correcly (?)

For the record, here's how my CMAKE builds it (I tested and it works but tells me that I need multple video adapters and aborts prematurely)

C:\mingw64\bin\g++.exe -msse -W -Wall -Wpointer-arith -Os -DNDEBUG -mwindows -Wl,-subsystem,windows -Wl,--whole-archive CMakeFiles\ex_winfull.dir/objects.a -Wl,--no-whole-archive -o ex_winfull.exe -Wl,--out-implib,libex_winfull.dll.a -Wl,--major-image-version,0,--minor-image-version,0 ..\lib\liballegro-static.a ..\lib\liballegro_main-static.a ..\lib\liballegro_dialog-static.a ..\lib\liballegro-static.a -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -lwinmm -lpsapi -lshlwapi C:\Windows\System32\d3d9.dll C:\Windows\System32\dinput8.dll -lstdc++ -lglu32 -lopengl32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

wanton
Member #15,527
March 2014

Using your command gives me undefined reference to WinMain.

EDIT: That was using pkrcel's command, I'll try compiling from source as a last resort.

Go to: