Wednesday, February 20, 2013

Allegro the static beast

Recently I wrote an article on compiling Allegro. Please note this was only for a dynamically linked library.
Now for a statically built library!

This actually turns out to be a slight ordeal (for using with D).
First you need to recompile any dependency that you are using e.g. FreeType.
Because it did not build it using MultiThreaded instead with MultiThreaded Dll; MT vs MD.

Under the properties for the project, C/C++ and code generation look for runtime property. Change that to MT.
Make sure it is set to build a static library.
Rebuild it; Now copy it back into Allegro dependency directory for it. Remember to rename it as required.

Basically do the same for Allegro (all project starting with allegro in it). Remember you can select all of them at once by clicking the first and holding shift when clicking the last. When changing the above setting as with FreeType it will apply to all.

Also you probably want to reconfigure the build configuration for Visual Studio first using cmake. Build it without shared library support. Should be a property under cmake group to untick that.

The other thing I did was turn off default lib. To do this go to librarian, general and change ignore all default libraries to yes.

You should now have a build of Allegro for static linking.

For those who use it with e.g. AllegroD what I do is rename the libraries using bash (cygwin install should also work with msys from MingW).
for files in *-static.lib; do mv "$files" "${files%-static.lib}.lib"; done
Do that under the project directory (where the .libs are for Allegro).
Please note you need to copy all dependencies you are using e.g. FreeType like you did for Allegro.

Last you need to include some more libs for Windows. Because they were excluded for linking with Allegro, you don't have them.
To do this I used this code:
version(Windows) {
pragma(lib, "libfreetype.lib");
pragma(lib, "opengl32.lib");
pragma(lib, "gdi32.lib");
pragma(lib, "gdiplus.lib");
pragma(lib, "ole32.lib");
pragma(lib, "user32.lib");
pragma(lib, "winmm.lib");
pragma(lib, "PSAPI.lib");
pragma(lib, "shlwapi.lib");
}

Basically the only reason I have libfreetype.lib is because it is assumed by AllegroD that it is already included as part of Allegro. You do not need to handle the Allegro lib's as that is dealt with by AllegroD for adding a pragma for.

If your doing this for another language like c++ you probably won't need to include the pragmas. But if you get symbols missing errors *scary* you can try out each of these till you get a working build.

Please note you do not need to use zlib with D. It is already built into the application as it is part of the standard library here.

I hope this helps!

No comments:

Post a Comment