Reputation: 9
I've been browsing for a while and a lot of sources recommend using Allegro as a first time 2d Library for C++; however, in this day and age i have found no tuition on applying Allegro 5's libraries to Visual Studio 15.
Is this possible or am I having to downgrade to Visual Studio 2010?
Upvotes: 0
Views: 8718
Reputation: 603
Edit as of 2016: Currently the preferred method of installation of Allegro 5 (which is at version 5.2.1 at the moment) on Visual Studio is through NuGet Packages. The link is here. This is the easiest and quickest method to get Allegro, and is the one everyone should use. Tested on Visual Studio Community 2015.
Apparently the guides on the net seem to be outdated or seem to forget that the Official Site has recent and modern binaries ready for download. So here is how to setup Allegro:
First thing first, I will be using the Unstable branch, 5.1, since it is the one that has the new binaries. And Second, I will be using Visual Studio 2013 but it should be exactly the same for Visual Studio 2015 (Step 1 below has the only difference in the process you might encounter).
We will download Allegro 5 direct from the Gna! repository. Here you select the file depending on what you have and what you want to do.
This directory has 4 files, in my case, I will download allegro-msvc2013-x86-5.1.12.zip and you will download allegro-msvc2015-x86-5.1.12.zip. Select the x64 version only if you know what you are doing.
When it finishes downloading, extract the contents somewhere that is easy to reach and that you will not move, such as the root of your hardrive or inside Documents. I'll go with the root, usually drive C:
. After the extraction, you should have a folder in C:\allegro\
with the following content:
allegro\
|-bin\
|-include\
|-lib\
It is important you remember where you extracted the files as setting the environment correctly depends on its ability to locate this path.
Here we tell Visual Studio how to use Allegro. Open Visual Studio and create a new C++project/open the project you want Allegro to be used in. With the project open, right click its name on the solution explorer and open Properties then:
C:\allegro\include\
in its text field.C:\allegro\lib\
in its text field.allegro_monolith-debug.lib
in its text field.allegro_monolith.lib
in its text field.This is the part where we test everything worked...(or not, see next step after error)
Create a *.cpp file or use the one where your main function is located and change it to this small test program: (I give away all my rights to it and place it under public domain)
#include "allegro5\allegro5.h"
#include <iostream>
int main(int argc, char** argv)
{
al_init();
ALLEGRO_DISPLAY *display = nullptr;
al_set_app_name("Hello World from Allegro 5.1!");
display = al_create_display(640, 480);
if (display == nullptr)
{
std::cerr << "Well, something is not working..." << std::endl;
al_rest(5.0);
return EXIT_FAILURE;
}
al_clear_to_color(al_map_rgb(255, 255, 255));
al_flip_display();
al_rest(5.0);
return 0;
}
If after compiling and running you get a blank window that closes in 5 seconds then Allegro is ready! If not, post your error message and I'll take a look at what happened.
Where we solve the missing DLL error upon execution...
So the program should have compiled correctly and Visual Studio will now attempt to run it. Upon starting, the following might appear:
The solution is to copy on the Debug folder on the root of your project the allegro_monolith-debug-5.1.dll
file, so that it is located beside your program's .exe file. Similarly, on the Release folder you have to copy allegro_monolith-5.1.dll
beside that folder's executable. Both of this files should be on the allegro\bin\
directory of the downloaded archive. Keep in mind that you would probably need another dll from the ones I said, but it should also be included on the file you downloaded from Gna!.
Note: The package I linked to only provides the base Allegro 5 library, not its dependencies. Supposedly the release binary has them included but the Debug version may need you to link them manually. They are located here. Select the 1.2.0 package for the newest version of allegro 5.1.12.
Upvotes: 3
Reputation: 31
There is possible a bit different approach, starting from above post Step 3. Under "All Configurations" do the following:
Upvotes: 3