- Online Community Forums » Allegro Development » Creating executable files in Visual Studio

Creating executable files in Visual Studio
Member #15,590
April 2014

Heya Folks,
I'm a math teacher running a game programming class for high school students. We use allegro 5 to make some silly 8-bit style games, and the kids earn math credit for it! We've had tons of success over the past few years, with kids making everything from PONG to pacman to little platformers. However, with this question the fact that I'm a bit of a poser is showing, since my background is in math and education, not CS. I'm sorry my questions are super newbie.

I've been scouring the forums to try to figure out how to package kids' games into an executable file that they can put on a zip file and take home for their parents to play. Most of my efforts have been focused on attempting to make an installer using inno setup, since folks on the forum seem to think it's the easiest option. But I can't seem to get all of the required files added into the installer, or if I am, the directories are getting all mixed up. My biggest problem is that I don't really have the understanding of how Visual Studio (or any IDE) installs Allegro and in which directories- since it's been an option, we've just been pressing the "install Allegro" button in the NuGet packages option that MSVS has. Edgar R posted a list of dependencies in a post on the subject, but I don't even know where to find the files, or how to attach them to an inno setup package in a way that a computer could find them :(

Does anyone have any advice on good tutorials to understand the process better?
Also, if there are other options you'd recommend for newbie programmers like me and my students to create executable of our games with (other IDEs, other methods other than inno setup, etc), feel free to send them my way.

Jen M

p.s. any general recommendations for a high school programming class using Allegro are welcome too :D

Member #7,536
July 2006

I'd caution against an installer unless the tools "Just Work(tm)" for you. They don't really add much, if any, value and historically at least the software to create installers has been proprietary/nonfree, inconsistent, and subpar. At least in my experience. These days I know that Microsoft sort of ships built-in installers at least with the professional licenses, but I find they leave much to be desired.

The point is that an installer isn't really needed for you to be able to run the software on your computer. That's actually a more difficult way to do it. You sometimes need administrative privileges to install such things, and they often do an incomplete job of uninstalling so they end up leaving a mess on your computer after.

An easier approach is to just distribute a simple zip with the necessary files. For a simple program, all of the files can be in the same directory which makes it easier to distribute them too. Windows will happily load libraries from the same directory as the program without any environment setup.

For an Allegro game itself to work you need to bundle at least the Allegro library and its dependencies (all of the DLLs that Allegro relies on to access the operating system and hardware). I don't typically develop C or C++ programs in Visual Studio so I can't be sure what differs from .NET development so I have to speculate a little.

You can try this: right-click the game project in Visual Studio and see if there is a "Publish..." option. If so click it. That should start a wizard which will build and "deploy" the necessary files to some location. The wizard should prompt you for a location to deploy to, and the easiest option is just to another folder on the computer somewhere outside of the solution. For example, to a folder on the desktop or a user folder or whatever the school network allows. Keeping it outside of the existing Visual Studio solution will help to be confident that the output directory does not depend on Visual Studio (hopefully). Assuming this works, copy the output directory to another computer (e.g., at home) where you don't have Visual Studio installed. Then try to run the program. If you get this far and it doesn't work you can also upload a zip file containing this folder here for us to take a look at. Then we can try to run it and help to figure out what is missing (hopefully).

Alternatively, NuGet should have installed Allegro (and its dependencies, if there are any) into some subfolder of your Visual Studio solution. You can investigate this folder to see which NuGet packages are installed, and which files are inside of them. Unfortunately, I don't think there's much of a standard for the structure inside of them, but you can explore them and see what kinds of libraries (DLLs and LIBs) you can find. If the above publish option wasn't available, and you're desperate, you can try to just manually copy these files into a directory along side a copy of the game exe (which can typically be found inside of a bin directory of the game project, hidden by default from Visual Studio, but visible from Windows). With all of these files in the same directory the game should run on another machine without Visual Studio or Allegro installed. In fact, there's a chance that said bin directory will already contain all of the libraries and executables that you need meaning you only need to add any data files that the game uses (image or sound files, for example; if any) and copy all of that to another machine to test.

Essentially, you need to distribute Allegro, all of its dependencies, and possibly one or more DLLs from Visual Studio itself along with your game so that it is all in one place and can run without any installation needed. Ideally it'll work from a USB thumb drive or something so that it's easy for the students to show their friends or family without any installation needed. They should be able to run it directly off of the thumb drive, or just download to a single folder and run it directly.

Edgar Reynaldo
Member #8,592
May 2007

Well, I would guide you through it, but I can't get VS 2017 to find the Allegro Nuget package. EDIT Nevermind, I just have to not be dumb.

Okay, got Allegro 5 Nuget installed on a new solution. Your solution folder will contain a packages folder. This is where all your nuget packages are stored. Buried away in subfolders are .lib files and .dll files. You need the dlls. However, VS conveniently places the current configuration's dlls in the 'Debug' folder.

So your project looks like this :


You can find everything you need in the Debug folder. First, make sure you've set the library type for the configuration you're using. Go to project properties, and then select the Allegro 5 entry on the left after you've added it to your project using Nuget. Under Add-ons, enable all the addons. Under Library Type, select Dynamic Release - static runtime.

Now rebuild your solution.

Go to the Debug folder and copy the .exe and the .dlls there into another folder. Now copy all your data into your distribution folder. You only need one copy of the dlls for all of your programs.

To test your distribution, go to a command line. cd to the directory where you've stored your exes and dlls and data. Then enter the following commands (replacing game.exe with your student's game name) :

set path=

If all goes well, their game should run smoothly. Second, test the working directory of the game by doing the following :

mkdir test
cd test

If the game still runs, you've got your current working directory set up correctly. If it crashes or aborts, it's because it was looking in the wrong place for resources. See my example code below for instructions how to set the current working directory in your program.

Some warnings about distributing on CD (I think this would be nice, to distribute a CD of all your students games) - you can't write to a CD, so if your students programs need to save files, they need to save it to a different path, such as the one returned by al_get_standard_path. I might recommend ALLEGRO_USER_DOCUMENTS_PATH or ALLEGRO_USER_DATA_PATH (which may not exist yet).

To show you that it works, I put a tiny demo together.
Here's a zip file of the game, data, src, and dlls to run it.

Here is the code used :

1#include "allegro5/allegro.h" 2#include "allegro5/allegro_acodec.h" 3#include "allegro5/allegro_audio.h" 4#include "allegro5/allegro_video.h" 5#include "allegro5/allegro_primitives.h" 6#include "allegro5/allegro_image.h" 7#include "allegro5/allegro_font.h" 8#include "allegro5/allegro_ttf.h" 9 10#define _USE_MATH_DEFINES 11#include <cmath> 12#include <cstdio> 13 14const int sw = 800; 15const int sh = 600; 16 17int main(int argc , char** argv) { 18 19 if (!al_init()) { 20 printf("Allegro init failed.\n"); 21 return 1; 22 } 23 if (!al_install_audio() || !al_install_keyboard() || !al_install_mouse()) { 24 printf("Install failed.\n"); 25 return 2; 26 } 27 if (!al_init_font_addon() || !al_init_ttf_addon() || !al_init_acodec_addon() || !al_init_video_addon() || !al_init_image_addon() || !al_init_primitives_addon()) { 28 printf("Addon init failed.\n"); 29 return 5; 30 } 31 32 /// This is important, it sets our current working directory to the directory with our executable in it 33 ALLEGRO_PATH* p = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 34 al_change_directory(al_path_cstr(p, '\\')); 35 al_destroy_path(p); 36 p = 0; 37 38 al_set_new_display_flags(ALLEGRO_WINDOWED); 39 40 ALLEGRO_DISPLAY* d = al_create_display(sw, sh); 41 42 ALLEGRO_EVENT_QUEUE* q = al_create_event_queue(); 43 44 ALLEGRO_FONT* f = al_load_ttf_font("Verdana.ttf", -72, 0); 45 46 ALLEGRO_TIMER* t = al_create_timer(1.0 / 60.0); 47 48 ALLEGRO_SAMPLE* s = al_load_sample("Sensors7secs.wav"); 49 50 if (!d || !q || !f || !t || !s) { 51 printf("Failed setup.\n"); 52 return -1; 53 } 54 55 al_register_event_source(q, al_get_display_event_source(d)); 56 al_register_event_source(q, al_get_timer_event_source(t)); 57 al_register_event_source(q, al_get_keyboard_event_source()); 58 59 al_reserve_samples(2); 60 61 double elapsed = 0.0; 62 double pct = 0.0; 63 double animation_rate = 4.0; 64 65 bool quit = false; 66 bool redraw = true; 67 68 al_play_sample(s, 0.75f, 0.0f, 1.0f, ALLEGRO_PLAYMODE_LOOP, (ALLEGRO_SAMPLE_ID*)0); 69 70 al_start_timer(t); 71 72 while (!quit) { 73 if (redraw) { 74 al_set_target_backbuffer(d); 75 al_clear_to_color(al_map_rgb(0, 0, 0)); 76 77 ALLEGRO_TRANSFORM tran; 78 /// Draw some text in red 79 al_identity_transform(&tran); 80 al_translate_transform(&tran, -sw / 2, -sh / 2); 81 al_scale_transform(&tran, pct, pct); 82 al_translate_transform(&tran, sw / 2, sh / 2); 83 al_use_transform(&tran); 84 al_draw_multiline_textf(f, al_map_rgb(255, 0, 0), sw / 2, sh / 2 - al_get_font_line_height(f) + 5, 85 sw, al_get_font_line_height(f) + 10, ALLEGRO_ALIGN_CENTRE, "Hello Dr.\nMoriarty!"); 86 /// Draw the same thing in white over the top 87 al_identity_transform(&tran); 88 al_translate_transform(&tran, -sw / 2, -sh / 2); 89 al_scale_transform(&tran, pct, pct); 90 al_translate_transform(&tran, sw / 2 + 5, sh / 2 + 5); 91 al_use_transform(&tran); 92 al_draw_multiline_textf(f, al_map_rgb(255 , 255 , 255), sw / 2, sh / 2 - al_get_font_line_height(f) + 5, 93 sw, al_get_font_line_height(f) + 10, ALLEGRO_ALIGN_CENTRE, "Hello Dr.\nMoriarty!"); 94 95 al_flip_display(); 96 redraw = false; 97 } 98 99 do { 100 ALLEGRO_EVENT ev; 101 al_wait_for_event(q, &ev); 102 if (ev.type == ALLEGRO_EVENT_TIMER) { 103 redraw = true; 104 elapsed = ev.timer.count*(1.0 / 60.0); 105 pct = 1.0 - (sin((2.0*M_PI)*(elapsed / animation_rate) - M_PI) + 1) / 2.0; 106 pct *= 3.0; 107 if (pct < 0.001) { 108 pct = 0.001; 109 } 110 } 111 if ((ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) || (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)) { 112 quit = true; 113 } 114 } while (!al_is_event_queue_empty(q)); 115 116 } 117 118 return 0; 119}

As an aside,
I can show you how to build with MinGW-W64, and Code::Blocks or gcc using my binaries if you're interested in an alternate build solution. However, you already have everything setup with VS, so it might end up taking more time to get things going.

Member #907
January 2001

There will still be the question of the "Visual C++" runtime (often called vcredist)
There are 7 versions of it, ranging from 3 to 13Mb, so be sure to pick the one that matches your version of Visual Studio.

Edgar Reynaldo
Member #8,592
May 2007

That's a good point.

I'm so used to not having to worry about it with MinGW that I just forgot about it all together. :/

You can either redistribute the redistributable yourself, or you can direct your users where to go to install it. It won't install itself though, so they still have to do that.

There should be a way to static link the runtime somehow. Ask Siegelord how that works with MSVC though.

Member #7,827
October 2006

With Nuget, you need to change two settings in Project Properties to create exe's with no DLL dependencies outside of standard ones:

1. Switch Allegro library type to 'Static Monolith Release', found in 'Allegro 5 > Library Type'.

2. Switch the C/C++ runtime to a non-DLL version, e.g. 'Multi-threaded', found in 'C/C++ > Code Generation > Runtime Library'


Member #1,975
March 2002

Why not use Free Pascal? It is much cheaper than VS, open source, has one of the best open source IDEs out there and Allegro.pas (still beta but compatible with Delphi, yay!), and the language is much more high-level, simple and readable than C++, with a better object model (stolen copied by Java and C# among others), much simpler to compile and link than GCC, and has a big student material base and support, and game development forums (& 2 & wiki).

Just say ;D

Current projects: Allegro.pas | MinGRo

Member #2,902
November 2002

DrMoriarty do yourself a favor and use Code::blocks instead..
MUCH easier to configure. put allegro 5 anywhere and just link to it.
and do not forget to copy the DLL files, just stuff everything in the exe dir !.

Even better.. use a free LINUX based system, and teach your students the value of free software !;)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Member #7,536
July 2006

You're probably going to overwhelm the OP suggesting she change her entire development environment. :P Visual Studio should be a workable environment. There's no good reason for the OP to change that.

SiegeLord is the author of the NuGet package and one of the Allegro developers so probably the voice you should be focusing on. :)

Member #2,902
November 2002

Yes there is...

Code::Blocks is Free ! as is GCC.
Code::blocks is easy to customize to your preferences.
Visual studio ( and I use both, but only because I have to (C#) ) is giving you a hard time configuring it if you want anything else than standard.

Speaking of standard.. GCC always follows the ISO C and C++ standard, and we all know how Microsoft thinks about standards. And it forces certain habits and non standard code wich makes it harder to port your code to another platform.
Learn the standard first, NOT the exception ( even if that exception has a bigger market share)

And don't get me started on visual studio runtime dll mess ::)

And teaching your students there is something else than Microsoft, is very valuable
They'll thank you later !

( I hope I'm not sounding like Richard Stallman ;) )

This is also very nice for inspiration: Nature Of Code


Edgar Reynaldo
Member #8,592
May 2007

Bump for news of progress, further questions, etc...

Dr. Moriarty? Any news? I'd like to get a copy of your students game distro if I could. Do you include source code?

Go to: