The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Visual C++ Express 2005

From Allegro Wiki
Revision as of 05:37, December 23, 2006 by Awikiadmin (talk | contribs) (twiki import)
Jump to: navigation, search

Background

You must be running Windows 2000 or later to use Visual C++ Express. Your computer should have at least 56MB of RAM and about 2GB of free disk space for a complete install of Visual C++ Express, MSDN Library, and the Platform SDK.

  • It currently is a free download, but Microsoft may charge for it the future**.

Installing the Software

While it is possible to build Allegro with VC++ Express, it isn't a very pleasant task because VC++ Express doesn't come with the necessary Windows and DirectX libraries. Therefore, we will just make use of packaged binaries available from Allegro.cc.

First thing you need to do is download and install VC++ Express:

Next, you will want to install the Platform SDK. It technically is optional if you don't static link, but it is recommended. Follow the instructions from here:


Once that is installed, download the MSVC 8.0 binary package (useful note: use the MSVC 7.1 package instead if you are using MS Visual Studio .NET 2003, or 7.0 for Visual C++ .NET) from Allegro.cc:


You should also copy the three DLLs (in the bin folder) into your C:WindowsSystem32 folder.

Setting up a Project

We'll begin by setting up a project with debugging enabled. This is the configuration you should use when working on your project.

  1. Open up Visual C++ Express 2005 from the Start menu.
  2. Select File / New Project...
  3. Select Visual C++ / General / Empty Project
  4. Type in the name of your project.
  5. Select the parent folder for your project. (VC++ will automatically create a sub folder for your project.)
  6. Uncheck the option Create directory for solution.
  7. Select Project / Add New Item...
  8. Select Code / C++ File, enter main.cpp for the name, and press Add.

At this point, you have a blank C++ project. There are a couple configuration settings we need to change to get Allegro to work (make sure you have the Debug Configuration selected):

  1. Select Project / Properties....
  2. Under Configuration Properties / C/C++ / General, change Debug Information Format to Program Database for Edit & Continue (/ZI).
  3. Under Configuration Properties / C/C++ / Optimization, change Optimization to Disabled.
  4. Under Configuration Properties / C/C++ / Code Generation, change Runtime Library to Multi-threaded Debug DLL (/MDd).
  5. Under Configuration Properties / Linker / Input, add alld.lib to Additional Dependencies.
  6. Under Configuration Properties / Linker / Debugging, change Generate Debug Info to Yes (/DEBUG).
  7. Press OK.

That's it! Now we can write our first Allegro application in Visual C++ Express. Copy and paste this code to your main.cpp file:

<highlightSyntax language="cpp">#include <allegro.h>

int main(void) {

  allegro_init();
  allegro_message("Hello World!");
  return 0;

} END_OF_MAIN()

</highlightSyntax>

Now press F7 to build the project. There should be no errors. Press CTRL-F5 to run it. If all goes as expected, you should see a message box with the text Hello World.

Using the Debugger

One of the nicest features of Visual C++ Express is its debugger. To use it with Allegro, make sure you are running your project in a Windowed mode. It does not work well with a full screen application.

To use the debugger, first make sure you are using a Debug configuration. The active configuration is listed to the right of the green arrow on the toolbar. To begin a debugging session, just press F5. Your application will run as normal as long as nothing crashes. A benefit to using the debug mode is that VC will automatically look for bad pointers and tell you when you try to use them.

You can set breakpoints by placing the cursor on a line and pressing F9. When the program reaches that line of the code, it will pause the execute and let you investigate things. You can then view and adjust the values of variables. Once you are finished, you can press F5 to continue again. Try adding a breakpoint on the allegro_message line and see what happens when you Debug (F5).

Advanced Options

As of now, we just have the Debugging version of Allegro configured. While this is the version you should use to develop your project, you'll also want to at least configure the Release (optimized) version for distribution.

Visual C++ Express lets you set up a variety of different build versions. With Allegro, the following can be set up:

  • Release
  • Debug (we set this one up already)
  • Profile
  • Static Release
  • Static Debug
  • Static Profile

The Static versions are different from the normal ones in that no Allegro DLL is needed. Instead, all the relevent Allegro code is included in the executable. This makes the file a bit larger, but easier to distribute.

The Release version is the one you should use when distributing your project. The Debug version is the one you should use when developing your project. The Profile version is the one you should use when trying to determine where the bottlenecks are. (Note that the Profile version isn't altogether very useful, because it just gives you more detailed information on Allegro's code as oppposed to your own.)

To get started, select Project / Properties... from the menu. On the top left, you should see a drop down called Configuration. Two versions are already present: Debug and Release. If you want to add Profile or Static configurations, see the next sub-section. If you don't, you can skip it.

Adding new Configurations

  1. Press Configuration Manager....
  2. Under Active Solution Configuration, select <New...>
  3. Give it a name (from one of the above six configurations)
  4. Press OK.

You'll need to repeat steps 1-3 for every configuration you want to add. Note that both the Release and Debug configurations are already created (although not configured) by default. So you only need to add configurations if you want to work with Static or Profiling versions.

Working with Configurations

Once you've added all the configurations that you want to use, you need to set them up. To do so, first select the configuration from the drop down box on the top left. After you do that, you can alter the settings specific to that configuration. The following table is a listing of all the settings that need to be changed for each configuration to get Allegro to work.

Configuration Key Value
Release C/C++ / Code Generation / Runtime Library Multi-threaded DLL (/MD)
^ Linker / Input / Additional Dependencies alleg.lib
Debug C/C++ / General / Debug Information Format Program Database for Edit & Continue (/ZI)
^ C/C++ / Optimization / Optimization Disabled
^ C/C++ / Code Generation / Runtime Library Multi-threaded Debug DLL (/MDd)
^ Linker / Input / Additional Dependencies alld.lib
^ Linker / Debugging / Generate Debug Info Yes (/DEBUG)
Profile C/C++ / Code Generation / Runtime Library Multi-threaded DLL (/MD)
^ Linker / Input / Additional Dependencies allp.lib
Static Release C/C++ / Preprocessor / Preprocessor Definitions ALLEGRO_STATICLINK
^ C/C++ / Code Generation / Runtime Library Multi-threaded DLL (/MD)
^ Linker / Input / Additional Dependencies alleg_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib
^ Linker / Command Line / Additional Options /LTCG
Static Debug C/C++ / General / Debug Information Format Program Database for Edit & Continue (/ZI)
^ C/C++ / Optimization / Optimization Disabled
^ C/C++ / Code Generation / Runtime Library Multi-threaded Debug DLL (/MDd)
^ Linker / Input / Additional Dependencies alld_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib
^ Linker / Debugging / Generate Debug Info Yes (/DEBUG)
Static Profile C/C++ / Preprocessor / Preprocessor Definitions ALLEGRO_STATICLINK
^ C/C++ / Code Generation / Runtime Library Multi-threaded DLL (/MD)
^ Linker / Input / Additional Dependencies allp_s.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib

(If anyone wants to make a Project Wizard/Template to eliminate the need to hand edit configuration settings, it would be much appreciated! Post a link to it if you ever make one...)

Notes

This article was written by MatthewLeverton. If you have anything to add to the article, please place it below in the Comments section. If it is valuable information, it will be added to the body of the article.

Comments

(Put your comments or questions in here. Please refrain from posting any comments that don't add anything to the article.)