The Allegro Guide
General » Windows » MSVC 7 » Using Allegro
I. Creating a Project
Using Allegro with Microsoft Visual Studio is simple once you get the workspace
configured. For most applications, you will want to use a "Win32 Application" and
link against the optimized library. While writing the code, however, you will
probably want to use the debugging and profiling modes. We are assuming you already
have Allegro already installed for MSVC 7.
A. Configuring a Win32 Application
If you want to create a game with graphics, then you need to create a 'Win32 Application'
workspace. (figure 1)
- Open Microsoft Visual Studio .NET
- Click on File / New / Project
- Choose "visual C++ Projects" / "Win32 Project"
- Enter your project Name, choose a Location and hit "OK"
- Select "Application Settings" and choose "Empty project"
- Hit "Finish"
Your workspace has been set up, but now we need to link to the Allegro library. You
technically only need to set up the optimized or debugging version, but it's recommended
to set up all three versions of Allegro - including the profiling. Remember that you
must have already built all these versions of Allegro before you can use them!
In order to get to the settings, you will need to Right-click on the Project Name
in the "Solution Explorer" and choose "Properties".
(figure 2)
- Click "Configuration Manager..."
- Select "<New...>" from the "Active Solution Configuration" drop down.
- Enter "Profile" in the "Solution Configuration Name".
- Hit "OK".
Now that we have all the configurations in place, we must set them up. We need to make the decision now if we
want to statically link or dynamically link. Dymamically linking means that you must distribute the Allegro DLL
along with your files. If you statically link, your executable will be much bigger (the size of the DLL), but you
will not need to distribute the DLL. If you have more than one executable, you should probably link dynamically
to save space. If you want to be able to use both methods, then you can repeat the steps 1-4 from above and add three more
configurations entitled "Static Release, "Static Profile", and "Static Debug".
In short, you only need to do one or the other. If you are not sure, then linking dynamically is the safer
option.
1. Dynamically Linking
Debug Build
- Under the Configuration drop-down, choose "Debug"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Code Generation"
- Select "Multi-threaded Debug DLL" in "Runtime Library"
- In the folder tree, choose "Configuration Properties" / "Linker" / "Input"
- Enter "alld.lib" in "Additional Dependencies"
- Click "Apply"
Optimized (Release) Build
- Under the Configuration drop-down, choose "Release"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Code Generation"
- Select "Multi-threaded DLL" in "Runtime Library"
- In the folder tree, choose "Configuration Properties" / "Linker" / "Input"
- Enter "alleg.lib" in "Additional Dependencies"
- Click "Apply"
Profile Build
- Under the Configuration drop-down, choose "Profile"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Code Generation"
- Select "Multi-threaded DLL" in "Runtime Library"
- In the folder tree, choose "Configuration Properties" / "Linker" / "Input"
- Enter "allp.lib" in "Additional Dependencies"
- Click "Apply"
2. Statically Linking
(Note: If you have chosen to configure both dynamic and static links, make sure to select the Static configurations
in the steps below.)
Static Debug Build
- Under the Configuration drop-down, choose "Debug"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Code Generation"
- Select "Multi-threaded Debug DLL" in "Runtime Library"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Preprocessor"
- Enter "ALLEGRO_STATICLINK" in "Preprocessor Definitions"
- In the folder tree, choose "Configuration Properties" / "Linker" / "Input"
- Enter "alld_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib" in "Additional Dependencies"
- Click "Apply"
Static Optimized (Release) Build
- Under the Configuration drop-down, choose "Release"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Code Generation"
- Select "Multi-threaded DLL" in "Runtime Library"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Preprocessor"
- Enter "ALLEGRO_STATICLINK" in "Preprocessor Definitions"
- In the folder tree, choose "Configuration Properties" / "Linker" / "Input"
- Enter "alleg_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib" in "Additional Dependencies"
- Click "Apply"
Static Profile Build
- Under the Configuration drop-down, choose "Profile"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Code Generation"
- Select "Multi-threaded DLL" in "Runtime Library"
- In the folder tree, choose "Configuration Properties" / "C/C++" / "Preprocessor"
- Enter "ALLEGRO_STATICLINK" in "Preprocessor Definitions"
- In the folder tree, choose "Configuration Properties" / "Linker" / "Input"
- Enter "allp_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib" in "Additional Dependencies"
- Click "Apply"
The workspace is entirely configured now! Skip down to the section entitled "Compiling Source Code" to get your
first program compiled.
B. Configuring a Console Application
If you just want to use Allegro for a text console, then you can follow the above instructions, except you
will need to choose "Win32 Console Application" when first creating the project. Also, you will need to define
"USE_CONSOLE" before you include <allegro.h>, as illustrated below.
II. Compiling Source Code
For the sake of simplicity, we will set up a program from one source file that should display the words "Hello World" in a pop up dialog box.
- Click on "File" / "Add New Item..."
- Choose "C++ File", enter the Name, and press "Open"
- Enter the following code:
#include <allegro.h>
int main(void)
{
allegro_init();
allegro_message("Hello World");
return 0;
}
END_OF_MAIN();
- Compile and Run the program. (CTRL-F5)
To select which configuration you want to build, simply choose "Build" / "Configuration Manager" and choose which one to use. Generally,
you will code your project with the Debugging version, test for performance with the Profiling version, and the release with the Release (Optimize)
version.