Building DOSBox with Visual Studio

From DOSBoxWiki
Revision as of 14:41, 27 June 2016 by Wengier (talk | contribs) (+link)
Jump to navigationJump to search

Note: The title of this page should actually be "Building DOSBox with Visual C++ 2008 Express", but the Wiki software does not allow the use of the + character in a title.

DOSBox is a complicated project. This document aims to provide a step by step description of how to use the free Express Edition of Microsoft's Visual C++ 2008 to successfully build DOSBox. An alternative is to use MinGW.

Get Visual C++ 2008 Express

Microsoft provides the Express edition of Visual C++ 2008 for free. Download VCE directly from Microsoft and install it. When installing, you don’t need to select any of the optional components like the Silverlight runtime, SQL Server or the MSDN Express Library. After the installation is complete, you will need to restart your computer.

Get the SDL library

To be able to build DOSBox, you will also need the development libraries for SDL. At the time of writing, the most current release of SDL is 1.2.13. From the downloads section at the SDL website look for the Development Libraries for Win32, marked for Visual C++ 2005 Service Pack 1. The filename will be something like SDL-devel-1.2.13-VC8.zip. Unpack this file to the location of your choosing. For this discussion, I shall place it in C:\Development\SDL-1.2.13.

Get the DOSBox sources

The next step is to get DOSBox itself. At the time of writing, the most current release of DOSBox is 0.74. Go to the DOSBox download page and download the DOSBox source. Since the DOSBox sources come as a .tar.gz file, you may need a separate program to extract this. Unpack the source to the location of your choosing. For this discussion, I have chosen C:\Development\dosbox-0.74.

Set up the environment

Setting the include directories for SDL

From your start menu, start VCE. After a few moments, the IDE (Integrated Development Environment) will start. The first thing we need to do is tell VCE where to find SDL. From the "Tools" menu select "Options". When the Options menu appears, expand the category "Projects and Solutions" and choose "VC++ Directories". From the directories pulldown, choose to show the directories for include files, click the folder icon and add the folder for the SDL includes. If you have been following this guide literally, that would C:\Development\SDL-1.2.13\include. Next, elect to show the directories for library files. This time, add the folder for the SDL libraries. When you have followed this guide, that would be C:\Development\SDL-1.2.13\lib.

After you have done this, click OK to accept and close the options.


Set up the solution

Conversion wizard

Conversion wizard

Open the solution provided by DOSBox. It can be found as C:\Development\dosbox-0.74\visualc_net\dosbox.sln. If you have file extensions hidden (as they are by default), you may select "Solution files (*.sln)" from the object type dropdown to ensure you get the correct one. The first time you open the solution, VCE will present you with the Visual Studio Conversion Wizard, because the solution included in the DOSBox distribution is for an older version of Visual C++. You can simply click Finish and be done with it. If you want, you can take a look at the conversion log, but the information in there is not particularly interesting.

Dependencies

Editing the additional dependencies

Now that the solution has been opened, it is necessary to disable some of the optional features of DOSBox. From the "Project" menu select "dosbox Properties". Expand the "Configuration Properties" and then the "Linker" category. Then choose "Input". From the properties on the right, you will need to remove some of the "Additional Dependencies". With the setup I have described here, I need to remove sdl_net.lib, zlib.lib, libpng.lib and curses.lib (you will also not need the odbc32.lib and odbccp32.lib references, but there is no harm in leaving them). Apply the changes and use the dropdown at the top left to switch to the Release configuration. Repeat the previous step, removing those same references and again apply the changes.

Configuration setup

Adjusting the config.h file

In the Solution Explorer, browse down the solution into "Source files" and then "visualc". Open the file config.h listed there and do some editing. Find the line that reads

#define C_SSHOT 1

and change the 1 to a 0. Do the same for the lines mentioning C_MODEM and C_IPX. The reason we are disabling these options is that they require some extra libraries that we haven’t set up for this tutorial. Also, set C_CORE_INLINE to 1 to enable faster CPU emulation.

In the Solution Explorer, in the "Source files", you will find the file winres.rc. Right-click on that and choose "View code". Remove the line at the top that reads

#include "afxres.h"

When you have done this, save the solution ("Save all" from the file menu). This ensures you won’t have to repeat any of the previous steps.

The actual build

Build successfully completed

Before building, right click on "Solution 'dosbox'" in the Solution Explorer and go to Properties -> Configuration Properties. Set the Configuration dropdown box to "Release" instead of "Debug". This will cause VC++ to build an optimized binary without extra debug features.

Now that all this is done, press F7 to start the build process. There will be a few warnings, but they are unimportant. The build may take a few minutes depending on the speed of your computer, but if you have followed this tutorial it will complete successfully.

Note that to actually run the executable you have built, you will need the SDL library (SDL.DLL) from your regular DOSBox install and place it in the C:\Development\dosbox-0.74\visualc_net directory.