Sunteți pe pagina 1din 3

Windows, Visual Studio 2010 and Allegro 5 About This guide explains how to get up and running with

Allegro 5. This setup assumes that there is no existing compiler installed. It is recommended to have a good fondation with C/C++ before starting with Allegro. A Microsof Visual Studio 2010 installation guide is included. If Visual Studio is already installed, goto the Installing Allegro 5 section. We will step through the process of installing Microsoft Visual Studio 2010 Expr ess, which is a free and featured C/C++ IDE from Microsoft. After that, we will download and install Allegro 5, create a new project, and build a small Allegro 5 example. As a note, when you see "5.0.x" in this article, the x is to be replaced by your current Allegro sub-version. Installing Microsoft Visual Studio 2010 Express Download: Download Visual C++ 2010 Express from Microsoft's website. It is free to download and use, and works great with Allegro 5. Run the MSVC 2010 Installer: Continue through the setup. Visual C++ 2010 is Ready: You should now be able to start Microsoft Visual C++ 2 010 Express, and see the Start Page. Installing Allegro 5 Download: Download the latest version of Allegro 5 from Allegro.cc's downlaod pa ge. Besure to select the binary version that corresponds with your version of MS VC. This tutorial may reference an older version number than what is available o n that page. While following the instructions, if you copy and paste something w ith a version number, be sure to update it to reflect the version you downloaded . Install Allegro 5 Headers and Libraries: Open allegro-5.0.x-msvc-10.0.zip and ex tract the folders: include, lib and bin to some place of your choosing. We will assume you've chosen C:\allegro as the base location for those three folders. We will later add this path to our project so VC can find Allegro. Note: Never cop y anythin into a system folder (like a path starting with C:\Program Files or C: \Windows). Those locations should generally be considered read-only unless using a proper installation "wizard". Keeping Allegro in its own folder will help you keep track of which version(s) you have installed. Also note that copying aDLL into system32 is not proper because a) you may overwrite an incompatible DLL an d b) it's not even the right location on 64-bit systems. Using Allegro 5 Create a New Project: Start Microsoft Visual C++ 2010 Express. Click New Project on the Start Page. Make sure Visual C++ is selected on the left. Now select Emp ty Project in the middle. Type a name for your project at the bottom, and feel f ree to change where your project is located. Click Ok to create your project. Add Some Source Code: Just to get you started, we will add some simple code to y our project that initializes the Allegro 5 library and opens a window. Right cli ck your project, under Solution Explorer on the right, and select Add -> New Ite m... Make sure Visual C++ is selected on the left. Select C++ file (.cpp) in the middle, and name your file main.cpp. Click Add. Now copy and paste the followin g code into your new file: #incude <stdio.h> #include <allegro5/allegro.h> int main(int argc, char **argv) { ALLEGRO_DISPLAY *display = NULL; if(!al_init()) {

fprintf(stderr, "failed to initialize allegro!\n"); return -1; } display = al_create_display(640, 480); if(!display) { fprintf(stderr, "failed to create display!\n"); return -1; } al_clear_to_color(al_map_rgb(0, 0, 0)); al_flip_display(); al_rest(10.0); al_destroy_display(display); return 0; } Save main.cpp. Setup Project For Allegro 5: For any project you create that uses Allegro 5, you must tell Visual C++ to link your project with the Allegro 5 library. Right cli ck your project under Solution Explorer on the right. Select Properties. ~Under Configuration Properties->C/C++->General, enter C:\allegro\include in Add itional Include Directories. ~Under Configuration Properties->Linker->General, enter C:\allegro\lib in Additi onal Library Directories. ~Under Configuration Properties->Linker->Input, append allegro-5.0.x-monolith-md -debug.lib to Additional Dependencies. ~Under Configuration Properties->Debugging, enter PATH=C:\allegro\bin;%PATH% in Environment. ~Click Apply. Visual C++ can now link your project with the Allegro 5 library. You should now select the "Release" configuration (upper left corner) and repeat the steps with one minor change: use the non-debug library allegro-5.0.x-monolith-md.lib. The monolith dll has the main Allegro module and all addons bundled into one fil e. If instead, you only want to add the main Allegro library and the ones for th e addons you use, in order to save space, you need to add allegro-5.0.x-md-debug .lib as well as allegro_(addon)-5.0.x-md.debug.lib. Build Your Project: Now let's have the Visual C++ compiler turn your beautiful n ew code into a program! Simply click the Debug menu at the top, and select Build Solution. If everything has gone well so far, you should see a successful messa ge at the bottom of the MSVC 2010 window. Run Your Project: Now to actually run your shiny new Allegro 5 program. Click th e Debug menu at the top and select Start Debugging. A black window should show u p. That is your first Allegro 5 window! It does not do much right now. It will d isplay for 10 seconds, and then close automatically. Static Linking: But wait, this method is for dynamic linking. What if you want i t so MSVCR100.dll and the Allegro libraries come packaged with the executable? Y ou'll have to change some things. You can do this just fot the Release configura tion, no need to do it for the Debug one. ~Add the following libraries to the linker in Configuration Properties->Linker-> Input: (Your standard Allegro library(ies), but with the -static-mt suffix. So, for instnace, allegro_image-5.0.x-static-mt.lib. This can be the monolith dll, or all addons separated.) dumb-0.9.3-static-mt.lib

freetype-2.4.8-static-mt.lib libFLAC-1.2.1-static-mt.lib libogg-1.2.1-static-mt.lib libvorbis-1.3.2-static-mt.lib libvorbisfile-1.3.2-static-mt.lib openal-1.14-static-mt.lib zlib-1.2.5-static-mt.lib winmm.lib opengl32.lib gdiplus.lib psapi.lib shlwapi.lib ~On the Configuration Properties->Linker->Input dialog box, leave the "inherit f rom parent or project defaults" option checked. ~In Configuration Properties->C/C++->Code Generation->Runtime Library, set that to "/MT" (or "/MTd" for the Debug configuration). ~In Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions, add ALLEGRO_STATICLINK to the list. ~Alternately, add #define ALLEGRO_STATICLINK to the top of your main fil e, before you include anything Allegro-related. This option is sometimes preferred, given that with dynamic linking, you'll have to distribute the dlls with the executable. This isn't normally a problem, but given that there are 2 version sof MSVCR100.dll, the 32-bit and 64-bit one, you can't distribute them both (as they have the same name). You might want to see if it runs on a machine that doesn't have the Visual C++ R untimes nor Allegro installed, to see if this single executable can runwithout t he need of any .dll file. There's always a chance something can go wrong. You'll need to have the Microsoft SDKs installed in order to compile like this. In addition, if you aren't going to use audio on your program, you won't need li braries like libogg or libvorbis, so if you want to save space, remove some libr aries that you think aren't needed, and see if it compiles.

S-ar putea să vă placă și