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.
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.
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.
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.
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.
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...
And where can I get those libraries?
The import libraries come with GCC, the DLL's are a standard part of Windows. It's all there.
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.
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
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.
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.
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.
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.
gcc probably already links against kernel32 by itself without telling explicitly since the c/c++ runtimes will need it.
Is there a decent old fashioned file search on W7?
Start -> Run -> cmd.exe >cd /d c:\ c:>dir /s myfile.ext .... .... Folder c:\blah myfile.ext 1234 ....