Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Static linking in VS2010 and A5 is giving errors

Credits go to Arthur Kalliokoski, Cassio Renan, torhu, and Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
Static linking in VS2010 and A5 is giving errors
André Silva
Member #11,991
May 2010
avatar

Sorry to bother, but I just can't find the answer myself. I'm trying to statically link Allegro 5 on Visual Studio 2010, but it's not working. I checked on the forums and Google and did all the steps that I could gather (release build):

  • #define ALLEGRO_STATICLINK before the Allegro #includes.

  • Compile with /MT (Multi-threaded, instead of Multi-threaded DLL).

  • Add the allegro_[library]-5.0.7-static-mt.lib libraries to the linker.

  • Add dumb-0.9.3-static-mt.lib, freetype-2.4.8-static-mt.lib, etc. libraries to the linker, after the Allegro ones.

  • Add -static to the command line (I think this is a g++ thing only, but I wanted to try everything.

But I keep getting errors like allegro-5.0.7-static-mt.lib(wxthread.obj) : error LNK2001: unresolved external symbol __imp__timeGetTime@0

I tried making sure the ALLEGRO_STATICLINK #define was well written (if it's wrong, it gives different errors), tried /MD, tried the -md.lib libraries (I get a OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp___unlink error in this case), tried having the inherit from parent or project defaults option checked, tried --static, I just tried everything.

There is no good tutorial out there for how you statically link with Allegro 5 on VS2010. I don't even know exactly what the effects are. With this, I know the dlls are "bundled" with the executable. This means I won't have to distribute the Allegro dlls or MSVCR100.dll with the program, right? Someone has to know!...

Arthur Kalliokoski
Second in Command
February 2005
avatar

Try linking winmm.lib?

They all watch too much MSNBC... they get ideas.

Cassio Renan
Member #14,189
April 2012
avatar

Try checking the wiki for the VS2008 installation. It's not the same version, but some things still apply.

here:

http://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2008_and_Allegro_5

André Silva
Member #11,991
May 2010
avatar

Odd, from what I've read around then, I should have opengl32.lib, gdiplus.lib, winmm.lib, psapi.lib on my Allegro 5's lib folder. Is this true? If not, does this mean I'll have to obtain those dlls somewhere else?

Trent Gamblin
Member #261
April 2000
avatar

They come with Windows/MSVC, you don't need to do anything but link to them (I think that usually means just writing "winmm" where you link libraries in MSVC -- but I'm not an MSVC user.)

Cassio Renan
Member #14,189
April 2012
avatar

Nope, it is not. I can't say for MSVC, but for MinGW they're all on the compiler's lib folder. You should check for such folder on your VS's installation.
The allegro lib folder only has dependencies for libraries such as zlib, libpng, flac, vorbis, etc; that aren't distributed with most compilers.

EDIT: Trent was faster.

André Silva
Member #11,991
May 2010
avatar

On my machine, those files were on C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib

Regardless, I added them to the list of libraries, even without specifying the folder, and it found them... but it's giving off different errors this time.

allegro-5.0.7-static-md.lib(fshook_stdio.obj) : error LNK2001: unresolved external symbol __imp___stat64i32
...
OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp__unlink
...
freetype-2.4.8-static-md.lib(psmodule.obj) : error LNK2001: unresolved external symbol __imp__qsort
...
OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp___fdopen

Arthur Kalliokoski
Second in Command
February 2005
avatar

Now MS can't even find libc? Switch to Mingw and stay there.

They all watch too much MSNBC... they get ideas.

André Silva
Member #11,991
May 2010
avatar

Excellent advice. But I did try compiling with g++ via command line once, without static linking. When I tried running it on another machine, it complained about libgcc or some such. I figure I'll have to add those libraries to the linker, sure, but seeing as we're on the topic, would I need to link anything else?
I can't wait to drop this awful piece of software. I just haven't already because it's a bit hard switching and such, not to mention the times my machine refuses to let Eclipse or NetBeans cooperate.

torhu
Member #2,727
September 2002
avatar

http://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2008_and_Allegro_5#Linker_Settings

Go back to what you originally did, but add the missing Windows libraries.

EDIT: If you want a better IDE, get Visual Studio 2008. Microsoft kind of lost their way after that.

Arthur Kalliokoski
Second in Command
February 2005
avatar

torhu said:

Microsoft kind of lost their way after that.

Aren't they changing to the Metro er, sorry, "Modern" way of doing things? Nice niche market they're making for themselves.

They all watch too much MSNBC... they get ideas.

André Silva
Member #11,991
May 2010
avatar

Ok, I have

allegro-5.0.7-static-mt.lib
allegro_font-5.0.7-static-mt.lib
allegro_image-5.0.7-static-mt.lib
allegro_primitives-5.0.7-static-mt.lib
allegro_ttf-5.0.7-static-mt.lib
dumb-0.9.3-static-mt.lib
freetype-2.4.8-static-mt.lib
libFLAC-1.2.1-static-mt.lib
libogg-1.2.1-static-mt.lib
libvorbis-1.3.2-static-mt.lib
libvorbisfile-1.3.2-static-mt.lib
openal-1.14-static-mt.lib
zlib-1.2.5-static-mt.lib
winmm.lib
opengl32.lib
gdiplus.lib
psapi.lib
msvcrt.lib
libcmt.lib
shlwapi.lib

added, and it did compile this time! Problem though: It didn't do anything, as the executable still asked for msvcr100.dll when trying to run on a different machine. The Allegro libraries were successfully packaged though, because when I tried pasting msvcr100.dll onto the folder, it worked, even though the graphics were garbled. So while it did package the Allegro libs, it didn't package the runtime libs. Still not resolved then...

I also found this thread, which I failed to find beforehand, but nothing there was able to help me either.

Also I just checked again to be sure. /MT, the ALLEGRO_STATICLINK #define is fine, everything seems to be in order. Guess I should just turn to MinGW and Eclipse, huh. But can we at least try to find the solution? At least if not for me, for anyone else who stumbles upon this thread and tries to statically link.

torhu
Member #2,727
September 2002
avatar

msvcrt.lib
libcmt.lib

Remove those, the compiler adds them based on the /MT and /MD setting. libcmt.lib is the static C runtime, while msvcrt.lib is the import library for msvcr100.dll ;)

André Silva
Member #11,991
May 2010
avatar

Hah! It worked! Thank you. So, to recap, in order to statically link Allegro 5 and the Visual C++ runtimes on Visual Studio 2010...

  • You add the following libraries to the linker:

    • allegro-5.0.7-static-mt.lib

    • allegro_(addon)-5.0.7-static-mt.lib

    • dumb-0.9.3-static-mt.lib

    • freetype-2.4.8-static-mt.lib

    • libFLAC-1.2.1-static-mt.lib

    • libogg-1.2.1-static-mt.lib

    • libvorbis-1.3.2-static-mt.lib

    • libvorbisfile-1.3.2-static-mt.lib

    • openal-1.14-static-mt.lib

    • zlib-1.2.5-static-mt.lib

    • winmm.lib

    • opengl32.lib

    • gdiplus.lib

    • psapi.lib

    • shlwapi.lib

  • Check the "inherit from parent or project defaults" checkbox on the linker library dialog box.

  • Go to C/C++, Code Generation, Runtime Library, and set it to "/MT" (or "/MTd" for debugging)

  • On the top of the main file, add "#define ALLEGRO_STATICLINK", or alternately, go to C/C++, Preprocessor, Preprocessor Definitions, and add "ALLEGRO_STATICLINK", after the other ones, keeping the "inherit from parent or project defaults" checkbox checked.

I tried creating a tiny program following these steps, and it worked. There was only the executable on the folder, I ran it, and it didn't ask for any Allegro library or for MSVCR100.dll. I hope this helps whoever has the same problem as me!

Thomas Fjellstrom
Member #476
June 2000
avatar

Note that some of those libs are optional if you don't use some of the addons. (vorbis, flac, freetype, openal, etc).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Cassio Renan
Member #14,189
April 2012
avatar

Since it seems that you got it summed up nicely, I guess this could go into the wiki. I could do it myself, but right now I don't have the time(also, I'm running ubuntu, so I can't do nothing more than copy/paste stuff here, unable to test anything). I can do it later this week, though, if nobody applies for the job.

André Silva
Member #11,991
May 2010
avatar

I have experience with wikis, and honestly, I don't think this'll take that long to do. I'll handle it tomorrow! :)

Go to: