Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Static linking

Credits go to Edgar Reynaldo, Matthew Leverton, and torhu for helping out!
This thread is locked; no one can reply to it. rss feed Print
Static linking
Johan Halmén
Member #1,550
September 2001

I use Code::Blocks and precompiled versions of Allegro (4.2 and 4.4). The dynamic linking works like a charm, but forces me to include a lot of dll with the distribution. I try to link with the static libs, but I get a lot of errors. I've found a lot of discussions about this on a.cc, but can't get the whole picture of it. What I've tried to do is link with libjpgalleg-2.6-static-md.a and liballegro-4.4.2-monolith-static-mt.a and #define ALLEGRO_STATICLINK. Is it so that I still need to link with this and that, because I get some 40 undefined references:

undefined reference to `midiOutSetVolume@8'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\allegro-4.4.2-mingw-4.5.2
\lib\liballegro-4.4.2-monolith-static-mt.a(wmidi.o):wmidi.c:(.text+0x1a7): undefined reference to `midiInStop@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\allegro-4.4.2-mingw-4.5.2
\lib\liballegro-4.4.2-monolith-static-mt.a(wmidi.o):wmidi.c:(.text+0x1b5): undefined reference to `midiInReset@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\allegro-4.4.2-mingw-4.5.2
\lib\liballegro-4.4.2-monolith-static-mt.a(wmidi.o):wmidi.c:(.text+0x1c3): undefined reference to `midiInClose@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\allegro-4.4.2-mingw-4.5.2
\lib\liballegro-4.4.2-monolith-static-mt.a(wmidi.o):wmidi.c:(.text+0x1e7): undefined reference to `midiOutReset@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\allegro-4.4.2-mingw-4.5.2
\lib\liballegro-4.4.2-monolith-static-mt.a(wmidi.o):wmidi.c:(.text+0x1f5): undefined reference to `midiOutClose@4'

...among others. I don't even use anything sound related.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Matthew Leverton
Supreme Loser
January 1999
avatar

You need to link with the windows libraries if you static link. Winmm is the lib for the ones you've listed. If you don't know which library includes the functions, use Google to find out.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Here are the windows libraries you need to link with for static linking A4 :

-lkernel32
-luser32
-lgdi32
-lcomdlg32
-lole32
-ldinput
-lddraw
-ldxguid
-lwinmm
-ldsound

Also, don't mix -md and -mt libraries. Pick one kind and stick with it. Don't remember which is which.

Johan Halmén
Member #1,550
September 2001

You mean dynamic linking makes me independent of MS stuff, but if I want static linking (single exe distribution), I need lots of MSVC related libs to link with? Stuff that isn't in the binary packages in the a.cc file section? The packages do include stuff like liballegro-4.4.2-monolith-static-mt.a and libjpgalleg-2.6-static-md.a but not the windows libraries needed. Still don't see the big picture here.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Matthew Leverton
Supreme Loser
January 1999
avatar

You need to link with the MS libraries because the static Allegro ones reference them. But it won't introduce any new DLL dependencies because they are all standard with Windows.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

All those libraries have already been linked to the allegro dlls, so you don't need to link to them again if you're linking dynamically. If you link statically however, you need to link to them because it hasn't been done yet.

Either way, Allegro on Windows uses win32 libraries...

Johan Halmén
Member #1,550
September 2001

And where can I get those libraries?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

torhu
Member #2,727
September 2002
avatar

The import libraries come with GCC, the DLL's are a standard part of Windows. It's all there.

Johan Halmén
Member #1,550
September 2001

Great! Seems to work now. I only searched for the first file, libkernel32.a or kernel32.lib and couldn't find it, so I thought I had none of them. But I found all others in another folder. Don't know about the kernel32 thing, but seems I don't need it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Thomas Fjellstrom
Member #476
June 2000
avatar

Don't know about the kernel32 thing, but seems I don't need it.

That's usually something of a hard requirement. kernel32.dll is the library windows puts all of its OS interaction api, things like filesystem access, anything that doesn't fit in GDI and, user32, and shell32. Which is a lot ;D

Have you seen a libkernel32.dll.a file? or something similar? That'd be the import library for the dll. a libblah.a is usually a static lib on windows, not a dynamic lib. At least thats one of the conventions.

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

torhu
Member #2,727
September 2002
avatar

There's supposed to be a lib/libkernel32.a file. Install the w32api package from the MinGW site if it's missing. The easiest way is to use their installer, which will download updated versions of the packages you select.

Johan Halmén
Member #1,550
September 2001

I haven't found kernel32 yet. But as I said, it works without it. I might have the libkernel32.a somewhere on my HD, but I just noticed W7 won't tell me! The f***ing search thing is not working. I have a brand new laptop with W7 and I thought the search thing would find it for me, but it seems it only finds indexed files, files that I've already used. I tried to change settings for the search. Now it seems to search both file names and text snippets inside files. Is there a decent old fashioned file search on W7?

Ok, now I found the libkernel32.a, nicely in the same folder as all the other .a files. I must have missed it and I relied too much on W7. But as long as my project compiles fine, I won't put it there. I might drop off some of the other libs, too.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Thomas Fjellstrom
Member #476
June 2000
avatar

libkernel32.a is just an import library, makes linking with dlls saner. I think gcc is able to link directly against a dll if it finds one, but I'm not sure about that. At the very least, that folder you found all those .a files in is probably in the compiler's library search path, meaning you don't need to copy them anywhere. Also you don't want to distribute .a files anywhere anyhow. The only files you NEED to distribute are your executables, data files, and any DLLs that don't come with the OS.

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

Oscar Giner
Member #2,207
April 2002
avatar

gcc probably already links against kernel32 by itself without telling explicitly since the c/c++ runtimes will need it.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: