Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Creating a static library with Allegro

This thread is locked; no one can reply to it. rss feed Print
Creating a static library with Allegro
xsquid
Member #16,498
July 2016

I've been working on a game engine on top of Allegro, and I'd like to compile it as a static library so I can use it in other projects. I'm using Visual Studio, and I have the Allegro .lib files listed under "Librarian > General" as Additional Dependencies:

allegro.lib; allegro_font.lib; allegro_ttf.lib; allegro_image.lib; allegro_audio.lib; allegro_primitives.lib; allegro_acodec.lib;

This works fine; I'm able to use the resulting library in another project. The catch is that Allegro's .dll files are still required to be present. This is not a surprise, because I didn't add Allegro's static library files to my dependencies.

So, I tried replacing "allegro.lib" with "allegro_monolith-static.lib", and made sure "ALLEGRO_STATICLINK" was defined under "C/C++ > Preoprocessor".

But now when I use the resulting .lib in a new project, I get a ton of errors:

Error LNK1120 163 unresolved externals
Error LNK2001 unresolved external symbol _DirectSoundCreate8@12
Error LNK2001 unresolved external symbol _DirectSoundCaptureCreate8@12
Error LNK2001 unresolved external symbol __imp__wglGetProcAddress@4
Error LNK2001 unresolved external symbol __imp__glGetIntegerv@8
Error LNK2001 unresolved external symbol __imp__glGetString@4
...

and so on. What am I doing wrong?

bamccaig
Member #7,536
July 2006
avatar

Most likely you aren't getting all of Allegro's dependencies statically linked as well? That's the challenge with statically linking something like Allegro that is built upon several third party libraries. To have a true static library you need the entire chain statically linked, and that tends to be a lot of work...

xsquid
Member #16,498
July 2016

Thanks for the response!

That's what I was thinking. I went into the "AllegroDeps" folder and added all of the .lib files from there ("AllegroDeps.1.5.0.0\build\native\v140\win32\deps\lib") in the same fashion, but I received the same set of errors.

I don't have any problem static linking Allegro itself (i.e., without my library involved), so the dependencies must be available for static linking somewhere as well, right? I can't seem to find any other .lib files to add, though.

SiegeLord
Member #7,827
October 2006
avatar

You should use the Allegro nuget package, which will take care of the libraries you need to link: https://www.nuget.org/packages/Allegro, here's a tutorial: https://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2015_and_Nuget_Allegro_5

If you really want to do it manually, you also need to link things like: opengl32.lib winmm.lib Shlwapi.lib psapi.lib dsound.lib.

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

xsquid
Member #16,498
July 2016

I've attached a text file with most the deps for Allegro and Windows.

Thank you for the comprehensive list! I'll see if I can get it working with this. Thank you as well, SiegeLord. I'm actually currently using the nuget package, which I assumed contained all of the dependencies.

Which brings me to this question... There's one thing I'm curious about (this is my first time trying to create a static library). If I'm just using Allegro by itself, I can create a statically-linked standalone executable no-problem (the nuget package makes this really easy).

How is this possible when those .lib file dependencies don't seem to exist anywhere in the package? They weren't present in the AllegroDeps package, either. If I can statically-link with Allegro, how come I need to include all of these dependencies in addition to the Allegro libs when creating my own static library based on Allegro? They have to exist somewhere already, right? I figured they would already be somewhere inside the Allegro libs. That, or they're included with Windows by default, which I doubt.

Sorry if this is a stupid question. I really what's happening here.

SiegeLord
Member #7,827
October 2006
avatar

xsquid said:

That, or they're included with Windows by default, which I doubt.

That's actually what it is sort of. opengl32.lib comes either from Windows default installation, or from GPU drivers. dsound.lib and others come with Windows SDK that comes with MSVC.

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

bamccaig
Member #7,536
July 2006
avatar

Any idea what the license terms of these libraries is? Is it allowed to statically link them like this?

SiegeLord
Member #7,827
October 2006
avatar

Those are not actually statically linked, I don't think that's possible. Ultimately those libraries are part of the Windows kernel... you'd hardly be expected to statically link that.

"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: