Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Static build for windows

This thread is locked; no one can reply to it. rss feed Print
Static build for windows
Ian Lewis
Member #15,817
December 2014

Hello,

I'm porting my Allegro 5 project from Raspberry Pi to Windows. I'm using Code::Blocks. I made a dynamically-linked build, which worked fine, using the allegro binaries and MinGW from these links (I think provided by Edgar Reynaldo, on this forum).

https://sourceforge.net/projects/unofficialallegro5distribution
https://sourceforge.net/projects/unofficialmingw/

I thought the file structure was a bit untidy with all the .dlls sitting in the same directory as the executable, so I thought I'd try to make a statically-linked version. To do this, I think I need:

1. Allegro libraries, built for static linking
2. Allegro dependencies (e.g. freetype, flac, zlib etc), also built for static linking
3. The same version of the same compiler that was used to build these libraries.

I can then follow this tutorial:
https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5

and hopefully it will all work.

It seems that point 2. is the difficult one. The allegro distribution linked above has dlls for the dependencies, but no libs. There's another distribution here:
http://download.gna.org/allegro/allegro-deps/1.4.0/

which has libs for the dependencies, but they don't have 'static' in the filename, and when I tried linking to them anyway, I got lots of unresolved references :(

I'm also puzzled by MinGW version numbers. The MinGW site says that there is no overall version number for MinGW, so what is the number that people quote?

Can anyone help me to find what I need to make a static build? Or should I just give up and stick with lots dlls? :-/

Thanks,

Ian.

SiegeLord
Member #7,827
October 2006
avatar

If you're going to use the official dependencies (the ones from gna.org), then it's best to use the official binaries as well: http://download.gna.org/allegro/allegro-unstable-bin/5.1.13/.

Try that combination and see if there are any unresolved references left (make sure to link all the various Windows libraries like user32 etc).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Ian Lewis
Member #15,817
December 2014

Thanks for that. I think I'd tried that combination already. Here are the errors I get that way.

I've attached my linker settings page, for reference. It more-or-less matches the tutorial above, but I added some extra libs (jpeg, theora, physfs & jpeg) from the gna download, as I got fewer errors with them in!

Any ideas what I might be missing?

Cheers,

Ian.

||=== Build: Debug in gravstorm (compiler: GNU GCC Compiler) ===|
..\TurboRaketti\AllegroDLLs\a5113_new\liballegro_monolith-static.a(file_stdio.c.obj)||In function `file_stdio_ferrmsg':|
C:\dev\allegro_winpkg\universal\allegro\src\file_stdio.c|298|undefined reference to `_imp__strerror_s'|
..\TurboRaketti\AllegroDLLs\a5113_new\liballegro_monolith-static.a(debug.c.obj)||In function `vsnprintf':|
F:\msys64\mingw32\i686-w64-mingw32\Include\stdio.h|545|undefined reference to `__ms_vsnprintf'|
F:\msys64\mingw32\i686-w64-mingw32\Include\stdio.h|545|undefined reference to `__ms_vsnprintf'|
..\TurboRaketti\AllegroDLLs\a5113_new\liballegro_monolith-static.a(bstrlib.c.obj)||In function `vsnprintf':|
F:\msys64\mingw32\i686-w64-mingw32\Include\stdio.h|545|undefined reference to `__ms_vsnprintf'|
F:\msys64\mingw32\i686-w64-mingw32\Include\stdio.h|545|undefined reference to `__ms_vsnprintf'|
F:\msys64\mingw32\i686-w64-mingw32\Include\stdio.h|545|undefined reference to `__ms_vsnprintf'|
..\TurboRaketti\AllegroDLLs\a5113_new\liballegro_monolith-static.a(bstrlib.c.obj):F:\msys64\mingw32\i686-w64-mingw32\Include\stdio.h|545|more undefined references to `__ms_vsnprintf' follow|
..\TurboRaketti\AllegroDLLs\a5113_new\liballegro_monolith-static.a(wsystem.c.obj)||In function `al_win_safe_load_library':|
C:\dev\allegro_winpkg\universal\allegro\src\win\wsystem.c|723|undefined reference to `_imp__PathFindOnPathA@8'|
..\TurboRaketti\AllegroDLLs\a5113_new\libFLAC.a(stream_decoder.c.obj)||In function `file_seek_callback_':|
C:\dev\allegro_winpkg\universal\flac-1.3.1\src\libFLAC\stream_decoder.c|3348|undefined reference to `fseeko'|
..\TurboRaketti\AllegroDLLs\a5113_new\libFLAC.a(stream_decoder.c.obj)||In function `file_tell_callback_':|
C:\dev\allegro_winpkg\universal\flac-1.3.1\src\libFLAC\stream_decoder.c|3361|undefined reference to `ftello'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `crc32'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `crc32'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `inflateReset'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `adler32'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `adler32'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `crc32'|
..\TurboRaketti\AllegroDLLs\a5113_new\libpng16.a(png.obj):png.c|| undefined reference to `crc32'|
||error: ld returned 1 exit status|
||=== Build failed: 18 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

SiegeLord
Member #7,827
October 2006
avatar

So I just tried this, and here's a command that worked for me (with image, acodec and ttf addons):

gcc test.c -Iinclude -Llib -lallegro_monolith-static -lopengl32 -luser32 -lgdi32 -lshell32 -lshlwapi -lpsapi -lkernel32 -lole32 -lwinmm -ljpeg -lpng -lzlib -lvorbisfile -lvorbis -logg -ldumb -lflac -lfreetype -static-libgcc -static-libstdc++ -static -lpthread -lstdc++

If that doesn't work for you, make sure your gcc is the right version.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Ian Lewis
Member #15,817
December 2014

Hello,

Thanks for that, I've now got a project that builds (and even runs!) For the benefit of anyone else who has similar problems, some things that I have learnt are:

0: If you are trying to build your code and statically link it to a pre-built library(ies), you need exactly the same version of compiler (and probably the rest of the toolchain) that was used to build the libraries.

1: There are a number of projects called 'MinGW' or variants of it. So if you're trying to match someone else's MinGW toolchain, you first need to know which MinGW project they used, and then the version.

2: MinGW has many components, each with it's own version number. The version number that gets quoted is the version of gcc (I think...)

3: The official binaries and dependencies (linked here: https://www.allegro.cc/forums/thread/616006/0) use 'MinGW-w64' (https://sourceforge.net/projects/mingw-w64/) version 5.3.0. The sourceforge page lets you download an installer, which in turn will let you choose a version.

4: When you have installed MinGW, you should add <your mingw directory>\bin to your windows path. If you have more than one MinGW installation (because you've been trying to figure out which is the right version :) you should probably only have one path entry, or risk extreme confusion :)

5: Code::Blocks auto-detect (under Settings|Compiler|toolchain executables) doesn't work very well, especially if you have multiple versions of MinGW. So browse to the directory, and then to the program files (gcc, g++, g++, ar GDB/CDB debugger, windres.exe, mingw32-make worked for me...)

6: The libs should be added as per the tutorial here:
https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5
but you will also need libpng16.a and libjpeg.a (from the dependencies) and libshlwapi.a (from the MinGW libs). libpng16.a MUST appear ABOVE libzlib.a in the list. I had libshlwapi at the bottom of the list.

7: The tutorial says that you should add:
-static-libgcc
-static-libstdc++
to 'Other linker settings'. In addition, you will also need to add
-static
-lpthread

8: Don't forget to #define ALLEGRO_STATICLINK

I think that's all. Some of this was determined by trial-and-error and guesswork, so if anyone who knows better can correct me, please go ahead. I may try to update the wiki tutorial with some of this in due course.

Cheers,

Ian.

SiegeLord
Member #7,827
October 2006
avatar

Ian Lewis said:

The version number that gets quoted is the version of gcc (I think...)

GCC version is important, but also the distribution too, as they sometimes differ in the way they handle C++ exceptions (you'll see things like 'sjlj') and threads. I prefer to live in lala-land and support only one (namely, mingw-w64).

It'd be great if you added those things to the tutorial, glad you got it working!

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: