Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Static compiling MinGW

This thread is locked; no one can reply to it. rss feed Print
Static compiling MinGW
Ponkutsu
Member #16,562
September 2016

Hello!

I have been trying to compile an Allegro program using the static library in MinGW. I failed to do it manually in the command line so I tried with Code::Blocks using this guide: https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5.
It's a bit outdated though, and the library names doesn't match, and there are more libraries and at least one library missing in the latest Allegro 5.

Some questions:

1) Are you supposed to just copy the "lib" and "include" directories to MinGW's corresponding directories? How can you update Allegro if you just mix in files like that?

2) Are you supposed to pick x86 or x64 depending on the platform you compile on or is it that you pick what the target platform is for your program?

3) So to avoid mixing the Allegro files with the MinGW files I went with the Code::Blocks guide. Here is what I did so far:

*Installed MinGW with version 5.3.0 of gcc/g++.
*Installed Code::Blocks v16.01 separately.
*Downloaded Allegro v5.2.1.1 and dependecies v1.4.0 (took I while until I figured out that I needed these too, they don't appear on the main site).
*I followed to guide to link all the libraries and includes from Allegro, dependecies and those neeeded MinGW libraries into a Code::Blocks project.
*I also added extra flags -static and -lpthread as explained in this post: https://www.allegro.cc/forums/thread/616089.
*I took a known working program and tried to compile it.

I get two undefined references to "__ms_vsnprintf" errors.
I have no idea what I did wrong. I have gotten this to work before on an older Allegro 5 on another computer some years ago.

Thanks for any help.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Ponkutsu said:

I have been trying to compile an Allegro program using the static library in MinGW. I failed to do it manually in the command line so I tried with Code::Blocks using this guide: https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5.
It's a bit outdated though, and the library names doesn't match, and there are more libraries and at least one library missing in the latest Allegro 5.

That guide is pretty outdated....

Ponkutsu said:

1) Are you supposed to just copy the "lib" and "include" directories to MinGW's corresponding directories? How can you update Allegro if you just mix in files like that?

You can do it that way, but it's not a good way to do it, as you noted yourself. What you want to do is keep Allegro separate, and then set your compiler and linker search paths to include the "include" and "lib" folder of the allegro distribution respectively, using -I INCLUDE_DIR and -L LIB_DIR.

Ex.

mingw32-g++ -Wall -O0 -o game.exe -I c:\LIBS\Allegro5211_MinGW5302_Rel3\include -L c:\LIBS\Allegro5211_MinGW5302_Rel3\lib -lallegro_monolith-static -static -ldumb -lFLAC -lvorbisfile -lvorbis -lfreetype -logg -lpng16 -lzlibstatic -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -static-libstdc++ -static-libgcc

Ponkutsu said:

2) Are you supposed to pick x86 or x64 depending on the platform you compile on or is it that you pick what the target platform is for your program?

x86 is for 32 bit and x64 is for 64 bit. It depends on your compiler. MinGW by itself is only for x86.

Ponkutsu said:

3) So to avoid mixing the Allegro files with the MinGW files I went with the Code::Blocks guide. Here is what I did so far:

*Installed MinGW with version 5.3.0 of gcc/g++.
*Installed Code::Blocks v16.01 separately.
*Downloaded Allegro v5.2.1.1 and dependecies v1.4.0 (took I while until I figured out that I needed these too, they don't appear on the main site).
*I followed to guide to link all the libraries and includes from Allegro, dependecies and those neeeded MinGW libraries into a Code::Blocks project.
*I also added extra flags -static and -lpthread as explained in this post: https://www.allegro.cc/forums/thread/616089.
*I took a known working program and tried to compile it.

I get two undefined references to "__ms_vsnprintf" errors.
I have no idea what I did wrong. I have gotten this to work before on an older Allegro 5 on another computer some years ago.

Installing MinGW 5.3.0 is correct.
Installing the stand alone CodeBlocks 16.01 is correct.
Here's where you may have messed up. I don't know if the binaries SiegeLord provides for MSYS2 MinGW64 work with standalone MinGW. I'm guessing they don't.

I provide binaries for the stand alone MinGW 5.3.0-2 that include all the dependencies with it. These should work for you. Download the latest version from here :
Unofficial Allegro 5 distribution files

Ponkutsu
Member #16,562
September 2016

Ponkutsu said:

I have been trying to compile an Allegro program using the static library in MinGW. I failed to do it manually in the command line so I tried with Code::Blocks using this guide: https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5.
It's a bit outdated though, and the library names doesn't match, and there are more libraries and at least one library missing in the latest Allegro 5.

That guide is pretty outdated....
Ponkutsu said:

1) Are you supposed to just copy the "lib" and "include" directories to MinGW's corresponding directories? How can you update Allegro if you just mix in files like that?

You can do it that way, but it's not a good way to do it, as you noted yourself. What you want to do is keep Allegro separate, and then set your compiler and linker search paths to include the "include" and "lib" folder of the allegro distribution respectively, using -I INCLUDE_DIR and -L LIB_DIR.

Ex.

mingw32-g++ -Wall -O0 -o game.exe -I c:\LIBS\Allegro5211_MinGW5302_Rel3\include -L c:\LIBS\Allegro5211_MinGW5302_Rel3\lib -lallegro_monolith-static -static -ldumb -lFLAC -lvorbisfile -lvorbis -lfreetype -logg -lpng16 -lzlibstatic -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -static-libstdc++ -static-libgcc

Thanks, this works! I wonder why some guides insist on copying the library to the MinGW directories though.

Ponkutsu said:

2) Are you supposed to pick x86 or x64 depending on the platform you compile on or is it that you pick what the target platform is for your program?

x86 is for 32 bit and x64 is for 64 bit. It depends on your compiler. MinGW by itself is only for x86.

I see, official MinGW is only for 32-bit. I don't think I will make 64-bit programs anyway. And 32-bit is better for compatibility.

Ponkutsu said:

3) So to avoid mixing the Allegro files with the MinGW files I went with the Code::Blocks guide. Here is what I did so far:

*Installed MinGW with version 5.3.0 of gcc/g++.
*Installed Code::Blocks v16.01 separately.
*Downloaded Allegro v5.2.1.1 and dependecies v1.4.0 (took I while until I figured out that I needed these too, they don't appear on the main site).
*I followed to guide to link all the libraries and includes from Allegro, dependecies and those neeeded MinGW libraries into a Code::Blocks project.
*I also added extra flags -static and -lpthread as explained in this post: https://www.allegro.cc/forums/thread/616089.
*I took a known working program and tried to compile it.

I get two undefined references to "__ms_vsnprintf" errors.
I have no idea what I did wrong. I have gotten this to work before on an older Allegro 5 on another computer some years ago.

Installing MinGW 5.3.0 is correct.
Installing the stand alone CodeBlocks 16.01 is correct.
Here's where you may have messed up. I don't know if the binaries SiegeLord provides for MSYS2 MinGW64 work with standalone MinGW. I'm guessing they don't.

I provide binaries for the stand alone MinGW 5.3.0-2 that include all the dependencies with it. These should work for you. Download the latest version from here :
Unofficial Allegro 5 distribution files [sourceforge.net]

Thanks a lot! This helped, now I can compile in the command line as well as Code::Blocks.
I downloaded the file "Allegro5211_MinGW5302_Rel3.tar.7z" and it worked perfectly with official MinGW.

Audric
Member #907
January 2001

Ponkutsu said:

Thanks, this works! I wonder why some guides insist on copying the library to the MinGW directories though.

These are standard locations, so every makefile written with the assumption that the library is in default location will work.
Otherwise, every time you pick sources from someone else, you have to add "-I" and "-L" arguments in their build instructions. And the makefiles / cmake scripts that you build work only on your current machine.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Ponkutsu
Member #16,562
September 2016

I see, it really is troublesome to compile someone else's code like this. Still Allegro binaries doesn't come with an installer or anything so it's a pain to uninstall manually if you need to try another build. You might as well keep a batch file for compiling Allegro projects. Or a project template in an IDE that links everything. But if a project relies on a complicated makefile it might not work so well I guess.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Most projects worth their salt that use allegro will allow you to specify an install directory where allegro is located. If they don't, they're not all that useful. It's as simple as setting a few search directories in a codeblocks project, or setting an environment variable in cmake.

Go to: