Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Using Allegro 5 with CodeBlocks

This thread is locked; no one can reply to it. rss feed Print
Using Allegro 5 with CodeBlocks
LadyInRed7
Member #15,941
April 2015

Hey guys Im new to allegro and this forum.
I have downloaded CMake and the allegro sources,but dont know how to use it to make a dll of Allegro.
By the way,I just want to learn Allegro and know how to use it.Thats before using it to make one of my own games !!!;)

So here is the query,what library should I make, a shared one or a static library??
I want to learn first by the way,so I would be grateful if someone tells me about the right path.
And yes,I have never used CMake before,so I dont know how to use it.
Thnx for reading,
Yours friendly newbie,
LafyInRed7.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You can compile Allegro directly with MinGW, the compiler that comes with CodeBlocks. You can create either a "MinGW Makefiles" makefile to use directly with mingw, or a "CodeBlocks - MinGW Makefiles" Code Blocks project that uses mingw indirectly.

Anyway, first steps are to install MinGW and CMake properly. The MinGW distribution is usually installed in c:\mingw, or in some sub directory of code blocks, but I prefer the former as CB can easily detect it when it is in c:\mingw.

Next, make sure the \mingw\bin directory is on your path, so that gcc and g++ are on your path. You can do this through environment variables in the system settings control panel or set it at runtime from a command line by typing in :

set path=c:\mingw\bin;%PATH%

After that install the latest CMake and make sure to check the option to add cmake to your path so you can run it from the command line as easily as mingw.

Then the general steps are to :

cd allegro_source_directory
mkdir build
cd build
cmake -G "MinGW Makefiles" -DSHARED=[On | Off] -DCMAKE_BUILD_TYPE=[Release | RelWithDebInfo | Debug | Profiling] -DWANT_MONOLITH=[On | Off] ..
mingw32-make
mingw32-make install

In the step where you run cmake, replace "MinGW Makefiles" with one of the generators mentioned when running 'cmake --help' at the cmd line if you're not using MinGW directly. The options like this : [On | Off] mean to replace that with one or the other, and similarly with the build type. want monolith determines whether you build allegro as a single library or as several. The .. at the end means to look in the parent directory for the CMakeLists.txt file.

You should see what version of MinGW you're using first by running 'g++ --version' at a command line after adding \mingw\bin to the path.

I can't say one way or the other to use dynamic or static versions of the library ( the SHARED cmake variable ). Dynamic versions leave you dependent on dlls, but static versions are harder to link. All depends on how you want to distribute your programs as well.

LadyInRed7
Member #15,941
April 2015

Hey Edgar,I downloaded a separate installation of MinGW(except the one I had with CodeBlocks).I set the enviroment path to c:\mingw,but after checking if MinGW is in my path,I seem to be lost.

I am stuck in this line

cmake -G "MinGW Makefiles" -DSHARED=[On | Off] -DCMAKE_BUILD_TYPE=[Release | RelWithDebInfo | Debug | Profiling] -DWANT_MONOLITH=[On | Off] ..

Cmake asks the following question:-

CMake Error: The source directory "C:/C++ Programs/Games/allegro4.2/include" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

What do I do?

Pls help guys,I would be indebted...
And yes Im using Allegro 4.2 ;)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I set the enviroment path to c:\mingw

Just be careful to keep the rest of the path when changing a system environment variable from the control panel, or you could screw up a bunch of things.

You want to be in your build folder when running cmake and mingw32-make.

cd allegro_source
mkdir build
cd build

And the cmake command is like this :

cmake -G "MinGW Makefiles" -DSHARED=On -DCMAKE_BUILD_TYPE=Release ..

The .. means look in the parent folder for CMakeLists.txt

LadyInRed7
Member #15,941
April 2015

Hey Edgar,I was browsing the a.cc forums and I came across the unofficial distro of the Allegro 5.1 or something...
Should I use it?? Bcoz I have bought the Game Programming All in One 3rd edition and it uses allegro 4.2.
Anyways, when I try to make one simple example given from the book,the compiler says alplatf.h not found,even though when its there and when I explicitly say to compile and link it.
What do I do,can you help??? ???
I think I wont be able to make a dll anymore, I have given up. :'(

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

If you want to use binaries you need to have them match your compiler version.

Allegro 4 and Allegro 5 are completely separate libraries. They are not compatible with each other. You can use Allegro 4.4.2 as that is the latest version of Allegro 4, and that will still be compatible with your book. Otherwise you would have to learn an entirely different api to use Allegro 5 and your book wouldn't help you anymore.

I do offer binary distributions for MinGW 4.8.1 and Allegro 5.1.9 but like I said, those aren't compatible with your book.

LadyInRed7
Member #15,941
April 2015

Well, leaving the book aside, I can still makeup with Allegro 5.But before I do so,could you tell me how to use the dlls of the unofficial distro??
I mean how to I use the dlls to make a simple program in Allegro 5 ??I can follow the online tutorials,and I do know the C++ syntax but I dont know how to make a program with a dll.
Thnx for your patience Edgar!!!
And maybe now I will have to give the book to a libray !! :P

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

To use my binary distribution of MinGW use 7-zip to extract the archive. Move the compiler folder to c:\mingw and set your path variable.

To use the binary distribution of Allegro 5.1.9, you extract the binary and then set the appropriate include directories, which are the compiler include path for searching for headers (.h, .hpp), and the linker search path for finding *.a archive files. The binary distro comes with /bin, /include, and /lib folders. The dlls are in the bin folder, and you put them with your program. The include folder is for the compiler to know how to compile everything. The lib folder contains the *.a archive files that you need to link with. These are all project settings in CodeBlocks. I don't have CB handy atm so I can't guide you explicitly how to use them.

Edit
To set up your CB project to compile and link with allegro you need to do (see image below) :

1) Goto Project->Build Options in the menu
2) Under the Search Directories tab and the Compiler tab, add in the path to the include folder from the binary distribution (A519distro/include). Under the Linker Tab add in the path to the lib folder (A519distro/lib).
3) Under the Linker Settings tab above, for each configuration you have in your build (debug, release, etc...) set the link options to link to the correct .a file. You will use one of these commands to link :
-lallegro_monolith.dll
-lallegro_monolith-debug.dll
-lallegro_monolith-static
-lallegro_monolith-debug-static

This is telling the linker to link to liballegro_monolith.dll.a, liballegro_monolith-debug.dll.a, liballegro_monolith-static.a, or to liballegro_monolith-debug-static.a. You can add any of these in as a link library on the left hand side of the dialog as well.

{"name":"609399","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/6\/967d21488c2475ddf3c32b9719cc0c99.png","w":748,"h":536,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/6\/967d21488c2475ddf3c32b9719cc0c99"}609399

If you choose to link statically, there is a long list of other libraries you need to link to :

-ldumb
-lFLAC
-lvorbisfile
-lvorbis
-lfreetype
-logg
-lzlibstatic
-lgdiplus
-luuid
-lkernel32
-lwinmm
-lpsapi
-lopengl32
-lglu32
-luser32
-lcomdlg32
-lgdi32
-lshell32
-lole32
-ladvapi32
-lws2_32
-lshlwapi
-lopenal32
-lgcc_eh
-static-libstdc++
-static-libgcc

Polybios
Member #12,293
October 2010

I just noticed that msys2's package manager comes with a pre-built package for Allegro 5.0.11. I haven't noticed before, but I haven't done much Windows stuff for a long time.

Go to: