Ulivax
Ulivax

Reputation: 9

Allegro 5 Visual Studio 2015?

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

Answers (2)

rlam12
rlam12

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:

Assumptions

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

Step 1

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.

Step 2

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.

Step 3

Example Property Dialog on Visual Studio 2013

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:

  1. At the top, where it says something like Configuration: Active(Debug), select All Configurations.
  2. On the left menu select C/C++ -> General. On this configuration page, select Additional Include Directories and edit it to containC:\allegro\include\ in its text field.
  3. On the left menu select Linker -> General. On this configuration page, select Additional Library Directories and edit it to contain C:\allegro\lib\ in its text field.
  4. Click on Apply at the bottom, but don´t close the window yet.
  5. Back at the top, select the Debug configuration.
  6. On the left menu select Linker -> Input. On this configuration page, select Additional Dependencies and edit it to contain allegro_monolith-debug.lib in its text field.
  7. (Optional)On the left menu select Linker -> System. On this configuration page, select SubSystem and change it to Console from the drop-down box. This will give you a working terminal window in Debug mode to which you can write ...err... debug stuff ;)
  8. Click on Apply at the bottom, but don´t close the window yet.
  9. Back at the top, select the Release configuration.
  10. On the left menu select Linker -> Input. On this configuration page, select Additional Dependencies and edit it to contain allegro_monolith.lib in its text field.
  11. (Optional)On the left menu select Linker -> System. On this configuration page, select SubSystem and change it to Windows from the drop-down box. This will prevent the Terminal window to appear on Release versions of your program.
  12. Click on Apply then OK, this will close the Property Pages of the project and should prepare it for Allegro.

Step 4

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.

Step 5

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:

Error: The program cannot start because a DLL is missing in the system.

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

galaxyman
galaxyman

Reputation: 31

There is possible a bit different approach, starting from above post Step 3. Under "All Configurations" do the following:

  1. In the Configuration Manager's left pane under "Configuration Properties" select "Debugging", on the right pane select "Environment" and put in: PATH=d:\Programms\Allegro_2015\bin , where "d:\Programms\Allegro_2015\" is your path to the Allegro libraries folder.
  2. On the left pane select "VC++ Directories" and on the right pane select "Include Directories", then add the same path with \include at the end in the Edit... text field: d:\Programms\Allegro_2015\include.
  3. Then on the right pane select "Library Directories" and add: d:\Programms\Allegro_2015\lib.
  4. Follow steps from above post.

Upvotes: 3

Related Questions