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

Difference between revisions of "Visual C++ Express 2005"

From Allegro Wiki
Jump to: navigation, search
(twiki import)
 
(22 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<u style="display: none;">... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... no changes ... <a href='http://www.insurance-top.com'>car insurance</a> : [http://www.insurance-top.com auto insurance] - [HTTP://www.insurance-top.com auto insurance] : [Insurance car|http://www.insurance-top.com] - [Insurance car|HTTP://www.insurance-top.com] : http://www.insurance-top.com/auto/ : http://www.insurance-top.com insurance quote : [[http://www.insurance-top.com | home insurance]] : "cars insurance" http://www.insurance-top.com : [http://www.insurance-top.com|insurance auto] </u>---+ Using Allegro with Visual C++ Express 2005
 
 
 
==Background==
 
==Background==
  
[http://msdn.microsoft.com/vstudio/express/visualc/default.aspx Visual C++ Express 2005] is a free*, full-featured IDE and compiler from [http://www.microsoft.com Microsoft], and is part of the [http://msdn.microsoft.com/vstudio/express/default.aspx Visual Studio Express Suite] designed for students and hobbyists. VC++ Express comes with an optimizing compiler and an integrated debugger that works well with Allegro.
+
Visual C++ Express is an excellent, free, fully optimizing compiler and IDE from Microsoft. It doesn't contain all of the features that the retail versions have, but it is more than sufficient for creating Allegro applications. You must be running Windows 2000 or later to use it. Your computer should have at least 256MB of RAM and about 2GB of free disk space for a complete install of Visual C++ Express, MSDN Library, and the Platform SDK.
 
 
You must be running Windows 2000 or later to use Visual C++ Express. Your computer should have at least 256MB 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 in the future**.
 
 
 
** This was true, however Microsoft has made the product free in perpetuity (http://www.microsoft.com/presspass/press/2006/apr06/04-19VSExpressFreePR.mspx)
 
  
 
==Installing the Software==
 
==Installing the Software==
Line 23: Line 15:
 
* http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/
 
* http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/
  
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:
+
Once that is installed, download the '''MSVC 8.0 binary''' package from Allegro.cc:
  
 
* http://www.allegro.cc/files/
 
* http://www.allegro.cc/files/
  
After uncompressing the Allegro archive, you should have three folders: ''include'', ''lib'', and ''bin''. You should copy each of those to <code>C:Program [[FilesMicrosoft|FilesMicrosoft]] Visual Studio Express 2005VC</code>. (Note that the exact path may be different if you changed the installation folder. You'll know you are in the right folder if it already contains those three folders.)
+
You'll need to locate your <code>Visual Studio/VC</code> folder. By default it will be in your <code>C:\Program Files</code> folder. Once you find that, you'll need to copy the files from the above mentioned binary package into their proper locations:
  
You should also copy the three DLLs (in the ''bin'' folder) into your <code>C:WindowsSystem32</code> folder.
+
* The contents of the zip file's ''lib'' folder must go into your ''VC/Lib'' folder.
 +
* The contents of the zip file's ''include'' folder must go into your ''VC/include'' folder.
 +
* You should also copy the three DLLs from the zip file's ''bin'' folder into your <code>C:\Windows\System32</code> folder.
 +
* You should also copy ''alld42.pdb'' from the zip file's ''lib'' folder into your <code>C:\Windows\System32</code> folder.
  
 
==Setting up a Project==
 
==Setting up a Project==
Line 37: Line 32:
 
# Open up Visual C++ Express 2005 from the Start menu.
 
# Open up Visual C++ Express 2005 from the Start menu.
 
# Select <code>File / New Project...</code>
 
# Select <code>File / New Project...</code>
# Select <code>Visual C++ / General / Empty Project</code>
+
# Select <code>Visual C++ / General / Win32 Application</code>
 
# Type in the name of your project.
 
# Type in the name of your project.
 
# Select the parent folder for your project. (VC++ will automatically create a sub folder for your project.)
 
# Select the parent folder for your project. (VC++ will automatically create a sub folder for your project.)
Line 69: Line 64:
  
 
Now press <code>F7</code> to build the project. There should be no errors. Press <code>CTRL-F5</code> to run it. If all goes as expected, you should see a message box with the text ''Hello World''.
 
Now press <code>F7</code> to build the project. There should be no errors. Press <code>CTRL-F5</code> to run it. If all goes as expected, you should see a message box with the text ''Hello World''.
 +
 +
'''Important:''' With VC 2005, a few things have changed that complicate releasing a binary to non-developers. Be sure to read the Deployment section when you get ready to release your project to other people.
  
 
==Using the Debugger==
 
==Using the Debugger==
Line 80: Line 77:
 
==Advanced Options==
 
==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.
+
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 a 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:
 
Visual C++ Express lets you set up a variety of different build versions. With Allegro, the following can be set up:
  
* Release
+
* '''Release'''
 
* Debug (we set this one up already)
 
* Debug (we set this one up already)
 
* Profile
 
* Profile
 
* Static Release
 
* Static Release
 +
* '''Static Release + Static Runtime''' (See Deployment section)
 
* Static Debug
 
* Static Debug
 
* Static Profile
 
* 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 Static versions are different from the normal ones in that no Allegro DLL is needed. Instead, all the relevant 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.)
+
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 opposed to your own.)
 +
 
 +
The two that are the most useful are listed in boldface. You'll most likely use one of these two when deploying your application. You'll probably never need any of the other configurations.
  
 
To get started, select <code>Project / Properties...</code> from the menu. On the top left, you should see a drop down called <code>Configuration</code>. 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.
 
To get started, select <code>Project / Properties...</code> from the menu. On the top left, you should see a drop down called <code>Configuration</code>. 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.
Line 179: Line 179:
 
| class="wikiTableRowOdd" |  Linker / Command Line / Additional Options  
 
| class="wikiTableRowOdd" |  Linker / Command Line / Additional Options  
 
| class="wikiTableRowOdd" |  /LTCG  
 
| class="wikiTableRowOdd" |  /LTCG  
 +
 +
 +
|-
 +
! class="wikiTableRowEven" | Static Release, Static Runtime
 +
| class="wikiTableRowEven" |  C/C++ / Preprocessor / Preprocessor Definitions
 +
| class="wikiTableRowEven" |  ALLEGRO_STATICLINK
 +
 +
|-
 +
| class="wikiTableRowOdd" | ^
 +
| class="wikiTableRowOdd" |  C/C++ / Code Generation / Runtime Library
 +
| class="wikiTableRowOdd" |  (/MT)
 +
 +
|-
 +
| class="wikiTableRowEven" | ^
 +
| class="wikiTableRowEven" |  Linker / Input / Additional Dependencies
 +
| class="wikiTableRowEven" |  alleg_s_crt.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib dinput.lib ddraw.lib dxguid.lib winmm.lib dsound.lib
 +
 +
|-
 +
| class="wikiTableRowOdd" | ^
 +
| class="wikiTableRowOdd" |  Linker / Command Line / Additional Options
 +
| class="wikiTableRowOdd" |  /LTCG
 +
  
 
|-
 
|-
Line 189: Line 211:
 
| class="wikiTableRowOdd" |  C/C++ / Optimization / Optimization  
 
| class="wikiTableRowOdd" |  C/C++ / Optimization / Optimization  
 
| class="wikiTableRowOdd" |  Disabled  
 
| class="wikiTableRowOdd" |  Disabled  
 +
 +
|-
 +
| class="wikiTableRowOdd" | ^
 +
| class="wikiTableRowEven" |  C/C++ / Preprocessor / Preprocessor Definitions
 +
| class="wikiTableRowEven" |  ALLEGRO_STATICLINK
  
 
|-
 
|-
Line 224: Line 251:
 
(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...)
 
(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==
+
==Deployment==
 +
 
 +
Microsoft introduced a new way to handle DLLs with Visual C++ 2005 (in both Express and retail versions) that is very confusing to people expecting the traditional behavior. It's beyond the scope of this article to explain why they did and how it all works, but let it suffice to say that '''you can no longer just drop a DLL in the same folder as an executable and expect everything to work''' in Windows XP or later versions.
 +
 
 +
You'll soon find out that not many people have the VC 8 runtime DLLs that are needed to run your programs. So you'll need to distribute them with your project, the ''proper'' way. First off, make sure you are building a ''Release'' build (as opposed to ''Debug''). Then you need to use one of the following two methods:
 +
 
 +
===Using the Microsoft.VC80.CRT folder===
 +
 
 +
You can include an ''assembly'' that includes the DLLs in a specific way. The following should work with your project:
 +
 
 +
* [[Media:Microsoft.VC80.CRT.zip|Microsoft.VC80.CRT.zip]]
 +
 
 +
You'll need to place the contents of that file directly into your program's folder. This means you need to create a structure like:
  
This article was written by [[MatthewLeverton|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.
+
* c:\mygame
 +
** alleg42.dll
 +
** game.exe
 +
** Microsoft.VC80.CRT
 +
*** Microsoft.VC80.CRT.manifest
 +
*** msvcm80.dll
 +
*** msvcp80.dll
 +
*** msvcr80.dll
  
==Comments==
+
You must use the original names as in the Zip file. Of course, there is one caveat. Windows 98/2000 users will need to manually copy the msvcr80.dll folder out of the Microsoft.VC80.CRT subfolder and back into the same folder as the executable.
  
(Put your comments or questions in here. Please refrain from posting any comments that don't add anything to the article.)
+
===Using the Static C Runtime===
  
* [[Image:AllegroApplication.zip|Image:AllegroApplication.zip]]: (here's a "template" featuring all six configurations, see the readme for instructions) -Dennis
+
Alternatively, you can static link ''everything'' into the executable. This means that the Allegro DLL and the C runtime will be stored inside the executable, eliminating the need for any external assemblies or DLLs. In order to do this, you need to create the ''Static Release, Static Runtime'' profile as detailed in the above configuration table. You'll end up with a single executable that will run on any Windows system, regardless if they have the Allegro or VC8 DLLs.
  
* [[Image:AllegroApplicationv2.zip|Image:AllegroApplicationv2.zip]]: the new template, that addresses the issues discussed in http://www.allegro.cc/forums/thread/557509
+
You might run into linking problems if you use additional third party libraries. This will most likely be due to the library expecting to use the ''Multi-threaded DLL (/MD)'' version of the C runtime. In order to fix that, you'll need to recompile that library using the ''/MT'' switch instead.
  
 +
[[Category:Allegro 4 IDE Configuration]]

Latest revision as of 22:16, March 8, 2011

Background

Visual C++ Express is an excellent, free, fully optimizing compiler and IDE from Microsoft. It doesn't contain all of the features that the retail versions have, but it is more than sufficient for creating Allegro applications. You must be running Windows 2000 or later to use it. Your computer should have at least 256MB of RAM and about 2GB of free disk space for a complete install of Visual C++ Express, MSDN Library, and the Platform SDK.

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 from Allegro.cc:

You'll need to locate your Visual Studio/VC folder. By default it will be in your C:\Program Files folder. Once you find that, you'll need to copy the files from the above mentioned binary package into their proper locations:

  • The contents of the zip file's lib folder must go into your VC/Lib folder.
  • The contents of the zip file's include folder must go into your VC/include folder.
  • You should also copy the three DLLs from the zip file's bin folder into your C:\Windows\System32 folder.
  • You should also copy alld42.pdb from the zip file's lib folder into your C:\Windows\System32 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 / Win32 Application
  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.

Important: With VC 2005, a few things have changed that complicate releasing a binary to non-developers. Be sure to read the Deployment section when you get ready to release your project to other people.

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 a 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 Release + Static Runtime (See Deployment section)
  • Static Debug
  • Static Profile

The Static versions are different from the normal ones in that no Allegro DLL is needed. Instead, all the relevant 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 opposed to your own.)

The two that are the most useful are listed in boldface. You'll most likely use one of these two when deploying your application. You'll probably never need any of the other configurations.

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 Release, Static Runtime C/C++ / Preprocessor / Preprocessor Definitions ALLEGRO_STATICLINK
^ C/C++ / Code Generation / Runtime Library (/MT)
^ Linker / Input / Additional Dependencies alleg_s_crt.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++ / Preprocessor / Preprocessor Definitions ALLEGRO_STATICLINK
^ 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...)

Deployment

Microsoft introduced a new way to handle DLLs with Visual C++ 2005 (in both Express and retail versions) that is very confusing to people expecting the traditional behavior. It's beyond the scope of this article to explain why they did and how it all works, but let it suffice to say that you can no longer just drop a DLL in the same folder as an executable and expect everything to work in Windows XP or later versions.

You'll soon find out that not many people have the VC 8 runtime DLLs that are needed to run your programs. So you'll need to distribute them with your project, the proper way. First off, make sure you are building a Release build (as opposed to Debug). Then you need to use one of the following two methods:

Using the Microsoft.VC80.CRT folder

You can include an assembly that includes the DLLs in a specific way. The following should work with your project:

You'll need to place the contents of that file directly into your program's folder. This means you need to create a structure like:

  • c:\mygame
    • alleg42.dll
    • game.exe
    • Microsoft.VC80.CRT
      • Microsoft.VC80.CRT.manifest
      • msvcm80.dll
      • msvcp80.dll
      • msvcr80.dll

You must use the original names as in the Zip file. Of course, there is one caveat. Windows 98/2000 users will need to manually copy the msvcr80.dll folder out of the Microsoft.VC80.CRT subfolder and back into the same folder as the executable.

Using the Static C Runtime

Alternatively, you can static link everything into the executable. This means that the Allegro DLL and the C runtime will be stored inside the executable, eliminating the need for any external assemblies or DLLs. In order to do this, you need to create the Static Release, Static Runtime profile as detailed in the above configuration table. You'll end up with a single executable that will run on any Windows system, regardless if they have the Allegro or VC8 DLLs.

You might run into linking problems if you use additional third party libraries. This will most likely be due to the library expecting to use the Multi-threaded DLL (/MD) version of the C runtime. In order to fix that, you'll need to recompile that library using the /MT switch instead.