Difference between revisions of "Building DOSBox with Visual Studio"

From DOSBoxWiki
Jump to navigationJump to search
(probably worth warning about the current debugging situation because this is a severe problem)
 
(22 intermediate revisions by 9 users not shown)
Line 1: Line 1:
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.
+
While the official Windows build environment for DOSBox is [[Building DOSBox with MinGW|MinGW]], it may also be built in Visual Studio for users more comfortable with this.
  
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.
+
== Get Visual Studio ==
 +
Free versions of Visual Studio are available at: https://visualstudio.microsoft.com/
  
And I had the perfect place for a plant with blue flowers. , http://wwjiaiq.i-was-in-paris.com/how-to-perform-sexual-intercorse.html how to perform sexual intercorse,  912385, http://tikurnq.jesuisopen.fr/what-color-is-muslin.html what color is muslin,  iha, http://rnketro.makesgirlscrazy.com/how-large-is-cloverfield.html how large is cloverfield,  =OOO,
+
The free version of Visual Studio 2017 is called the "Community" edition. Prior to this (VS2005-2015) free versions were called the "Express" edition.
  
== Get the SDL library ==
+
Some older versions are available at: https://visualstudio.microsoft.com/vs/older-downloads/
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 [http://www.libsdl.org/ SDL website] look for the Development Libraries for Win32, marked for Visual C++ 2005 Service Pack 1. The filename will be something like <tt>SDL-devel-1.2.13-VC8.zip</tt>. Unpack this file to the location of your choosing. For this discussion, I shall place it in <tt>C:\Development\SDL-1.2.13</tt>.
 
  
== Get the DOSBox sources ==
+
When installing Visual Studio, there may be tools for multiple languages available (C++, C#, Visual Basic .NET, Java, etc.) but only the C++ tools are necessary for DOSBox.
The next step is to get DOSBox itself. At the time of writing, the most current release of DOSBox is 0.73. Go to [http://www.dosbox.com/download.php?main=1 the DOSBox download page] and download the DOSBox source. Since the DOSBox sources come as a <tt>.tar.gz</tt> 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 <tt>C:\Development\dosbox-0.73</tt>.
 
  
== Set up the environment ==
+
== Get Libraries ==
[[Image:Vce_guide1.png|thumb|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 <tt>C:\Development\SDL-1.2.13\include</tt>. 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 <tt>C:\Development\SDL-1.2.13\lib</tt>.
 
  
After you have done this, click OK to accept and close the options.
+
* Required: [https://www.libsdl.org/download-1.2.php '''SDL 1.2''']
 +
** https://www.libsdl.org/release/SDL-devel-1.2.15-VC.zip (VS2013 or earlier)
 +
** https://www.libsdl.org/release/SDL-1.2.15.zip (VS2015 or later)
  
<br style="clear:right;" />
+
* Optional for screenshots and video capture:
== Set up the solution ==
+
** [https://zlib.net/ '''zlib'''] - https://zlib.net/fossils/zlib-1.2.8.tar.gz
=== Conversion wizard ===
+
** [http://www.libpng.org/pub/png/libpng.html '''libpng'''] - https://download.sourceforge.net/libpng/lpng1634.zip
[[Image:Vce_guide2.png|thumb|Conversion wizard]]
 
Open the solution provided by DOSBox. It can be found as <tt>C:\Development\dosbox-0.73\visualc_net\dosbox.sln</tt>. 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.
 
<br style="clear:right;" />
 
=== Dependencies ===
 
[[Image:Vce_guide3.png|thumb|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.
 
<br style="clear:right;" />
 
=== Configuration setup ===
 
[[Image:Vce_guide4.png|thumb|Adjusting the config.h file]]
 
In the Solution Explorer, browse down the solution into "Source files" and then "visualc". Open the file <tt>config.h</tt> 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 <tt>C_MODEM</tt> and <tt>C_IPX</tt>. 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 <tt>C_CORE_INLINE</tt> to 1 to enable faster CPU emulation.
 
  
In the Solution Explorer, in the "Source files", you will find the file <tt>winres.rc</tt>. Right-click on that and choose "View code". ''Remove'' the line at the top that reads
+
* Optional for networking:
#include "afxres.h"
+
** [https://www.libsdl.org/projects/SDL_net/release-1.2.html '''SDL_net 1.2'''] - https://www.libsdl.org/projects/SDL_net/release/SDL_net-devel-1.2.8-VC.zip
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.
 
<br style="clear:right;" />
 
  
== The actual build ==
+
* Optional for compressed audio disc images:
[[Image:Vce_guide5.png|thumb|Build successfully completed]]
+
** [https://www.icculus.org/SDL_sound/ '''SDL_sound''']
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.
+
* Optional for DOS debugging tools:
 +
** [https://pdcurses.sourceforge.io/ '''PDCurses''']
  
Note that to actually run the executable you have built, you will need the SDL library (<tt>SDL.DLL</tt>) from your regular DOSBox install and place it in the <tt>C:\Development\dosbox-0.73\visualc_net</tt> directory.
+
== Prepare Libraries ==
 +
 
 +
=== SDL ===
 +
If using VS2013 or earlier, you can use the pre-built library in '''SDL-devel-1.2.15-VC.zip'''. For VS2015 or later you will need to rebuild it from source ('''SDL-1.2.15.zip'''):
 +
* Open '''SDL-1.2.15\VisualC\SDL.sln''' and allow Visual Studio to automatically convert the solution and project to the latest version.
 +
* Select the ''Release'' configuration and use the ''Build'' menu to build the solution.
 +
* The following 3 files should be built:
 +
** '''SDL-1.2.15\VisualC\Release\SDL.dll'''
 +
** '''SDL-1.2.15\VisualC\Release\SDL.lib'''
 +
** '''SDL-1.2.15\VisualC\SDLmain\Release\SDLmain.lib'''
 +
* The following folder also contains relevant include files for the library:
 +
** '''SDL-1.2.15\include'''
 +
* If you need more info on building SDL with VS, see: '''SDL-1.2.15\VisualC.html'''
 +
 
 +
=== zlib / libpng (optional) ===
 +
Enables screenshot and video capture.
 +
 
 +
Because '''zlib''' is a dependency of '''libpng''', a VS solution to build both at once is provided by the ''libpng'' package.
 +
 
 +
* Unpack '''lpng1634.zip''' to create the folder: '''lpng1634'''
 +
* Unpack '''zlib-1.2.8.tar.gz''' to create an adjacent folder: '''zlib-1.2.8'''
 +
* Open '''lpng1634\projects\vstudio\zlib.props''' with a text editor.
 +
** Near the bottom of the file you will find '''<DisableSpecificWarnings>'''. Add ''';5045''' to the end of this list. (This disables a new spurious warning in VS2017.)
 +
* Open '''lpng1634\projects\vstudio\vstudio.sln''' and allow Visual Studio to automatically convert the solution and projects to the latest version.
 +
* Select the '''Release Library''' configuration.
 +
* Right click on the '''zlib''' project in the solution explorer and open its '''Properties'''.
 +
** From '''Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions''' remove '''Z_SOLO'''. (Currently causes video capture to fail and crash.)
 +
** Change '''Configuration Properties > C/C++ > Code Generation > Runtime Library''' to '''Multi-threaded DLL (/MD)'''.
 +
* Right click on the '''zlib''' project and build it.
 +
* Now open the '''libpng''' project's properties.
 +
** Change '''Configuration Properties > C/C++ > Code Generation > Runtime Library''' to '''Multi-threaded DLL (/MD)'''.
 +
* Build the '''libpng''' project.
 +
* The following libraries should now be built:
 +
** '''lpng1634\projects\vstudio\Release Library\zlib.lib'''
 +
** '''lpng1634\projects\vstudio\Release Library\libpng16.lib'''
 +
* Include folders:
 +
** '''lpng1634'''
 +
** '''zlib-1.2.8'''
 +
* For more libpng build information see: '''lpng1634\INSTALL'''
 +
 
 +
=== SDL_net (optional) ===
 +
Enables networking.
 +
 
 +
You can use the pre-built libraries in '''SDL_net-devel-1.2.8-VC.zip'''.
 +
* Library files:
 +
** '''SDL_net-1.2.8\lib\x86\SDL_net.dll'''
 +
** '''SDL_net-1.2.8\lib\x86\SDL_net.lib'''
 +
* Include folder:
 +
** '''SDL_net-1.2.8\include'''
 +
 
 +
=== SDL_sound (optional) ===
 +
Enables the use of CD images with compressed audio.
 +
* Guide not yet written.
 +
 
 +
=== PDCurses (optional) ===
 +
Enables a DOS debugger.
 +
* Guide not yet written.
 +
 
 +
== Get DOSBox Source ==
 +
* If you plan on rebuilding periodically with the latest code, you can check out the Subversion repository here: https://sourceforge.net/p/dosbox/code-0/HEAD/tree/dosbox/trunk/
 +
* Otherwise you can download a snapshot of the latest DOSBox SVN source here: http://source.dosbox.com/dosboxsvn.tgz
 +
* See also [[SVN Builds]] for a list of unofficial alternative versions of DOSBox that you may wish to try instead. Many of them have additional features.
 +
 
 +
== Build DOSBox ==
 +
* After downloading the source code, open the Visual Studio solution: '''dosbox\visualc_net\dosbox.sln'''
 +
* Allow it to automatically convert to the latest version.
 +
* Right click the '''dosbox''' project in the Solution Explorer and open its '''Properties'''.
 +
** When editing the properties, edits will have to be made for each configuration you may want to build. In the top left there is an option for '''Debug''', '''Release''' and '''All Configurations'''. The ''Release'' build is most commonly used, but ''All Configurations'' will let you conveniently edit both at once wherever the two configurations have the same options.
 +
** Click the drop down triangle on '''Configuration Properties > C/C++ > General > Additional Include Directories''' and edit this list. Add the appropriate '''include path''' for each library prepared above. Keep in mind that paths are relative to the '''dosbox\visualc_net''' folder.
 +
** Edit '''Configuration Properties > Linker > General > Additional Library Directories''' and add the path to each library (.lib) file prepared above.
 +
** Edit '''Configuration Properties > Linker > Input > Additional Dependencies''' to add or remove libraries. (You will have to select either the Debug or Release configuration for this, as the Debug build uses a different list of libraries than the Release.)
 +
*** Remove '''zlib.lib''' and '''libpng.lib''' if not using these. Rename '''libpng.lib''' as '''libpng16.lib''' if you are using it.
 +
*** Remove '''sdl_net.lib''' if not using it.
 +
*** Add an entry for ''SDL_sound'' if using it.
 +
*** Remove '''curses.lib''' if not using it.
 +
* Find '''dosbox\src\platform\visualc\config.h''' and open it (in the solution explorer it is under '''dosbox \ Source Files \ visualc''').
 +
** '''C_SSHOT''' to 0 if not using ''zlib/libpng''.
 +
** '''C_MODEM''' and '''C_IPX''' to 0 if not using ''SDL_net''.
 +
** Add '''#define C_SDL_SOUND''' if using ''SDL_sound''.
 +
** '''C_DEBUG''' to 1 if using the ''PDCurses''.
 +
* After all of this is set up, you may build the '''dosbox''' project. Choose a ''Debug'' or ''Release'' configuration (recommend: ''Release'') and use the build menu to build the solution. One of the following will be built:
 +
** '''dosbox\visualc_net\Release\dosbox.exe'''
 +
** '''dosbox\visualc_net\Debug\dosbox.exe'''
 +
* Finally, take the '''SDL.dll''' and '''SDL_net.dll''' files prepared above and place them in the same directory as '''dosbox.exe'''. It should now be ready to run.
 +
 
 +
== Notes ==
 +
* When debugging with Visual Studio, breakpoints currently cause the host computer to slow to a crawl, making the debugger very difficult to use. Until a solution for this is found, you may wish to resort to "printf debugging" as a workaround, or alternatively consider building with [[Building DOSBox with MinGW|MinGW]] and using GDB to debug. ([https://www.vogons.org/viewtopic.php?f=32&t=60667 discussion])

Latest revision as of 00:41, 14 July 2018

While the official Windows build environment for DOSBox is MinGW, it may also be built in Visual Studio for users more comfortable with this.

Get Visual Studio

Free versions of Visual Studio are available at: https://visualstudio.microsoft.com/

The free version of Visual Studio 2017 is called the "Community" edition. Prior to this (VS2005-2015) free versions were called the "Express" edition.

Some older versions are available at: https://visualstudio.microsoft.com/vs/older-downloads/

When installing Visual Studio, there may be tools for multiple languages available (C++, C#, Visual Basic .NET, Java, etc.) but only the C++ tools are necessary for DOSBox.

Get Libraries

  • Optional for compressed audio disc images:
  • Optional for DOS debugging tools:

Prepare Libraries

SDL

If using VS2013 or earlier, you can use the pre-built library in SDL-devel-1.2.15-VC.zip. For VS2015 or later you will need to rebuild it from source (SDL-1.2.15.zip):

  • Open SDL-1.2.15\VisualC\SDL.sln and allow Visual Studio to automatically convert the solution and project to the latest version.
  • Select the Release configuration and use the Build menu to build the solution.
  • The following 3 files should be built:
    • SDL-1.2.15\VisualC\Release\SDL.dll
    • SDL-1.2.15\VisualC\Release\SDL.lib
    • SDL-1.2.15\VisualC\SDLmain\Release\SDLmain.lib
  • The following folder also contains relevant include files for the library:
    • SDL-1.2.15\include
  • If you need more info on building SDL with VS, see: SDL-1.2.15\VisualC.html

zlib / libpng (optional)

Enables screenshot and video capture.

Because zlib is a dependency of libpng, a VS solution to build both at once is provided by the libpng package.

  • Unpack lpng1634.zip to create the folder: lpng1634
  • Unpack zlib-1.2.8.tar.gz to create an adjacent folder: zlib-1.2.8
  • Open lpng1634\projects\vstudio\zlib.props with a text editor.
    • Near the bottom of the file you will find <DisableSpecificWarnings>. Add ;5045 to the end of this list. (This disables a new spurious warning in VS2017.)
  • Open lpng1634\projects\vstudio\vstudio.sln and allow Visual Studio to automatically convert the solution and projects to the latest version.
  • Select the Release Library configuration.
  • Right click on the zlib project in the solution explorer and open its Properties.
    • From Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions remove Z_SOLO. (Currently causes video capture to fail and crash.)
    • Change Configuration Properties > C/C++ > Code Generation > Runtime Library to Multi-threaded DLL (/MD).
  • Right click on the zlib project and build it.
  • Now open the libpng project's properties.
    • Change Configuration Properties > C/C++ > Code Generation > Runtime Library to Multi-threaded DLL (/MD).
  • Build the libpng project.
  • The following libraries should now be built:
    • lpng1634\projects\vstudio\Release Library\zlib.lib
    • lpng1634\projects\vstudio\Release Library\libpng16.lib
  • Include folders:
    • lpng1634
    • zlib-1.2.8
  • For more libpng build information see: lpng1634\INSTALL

SDL_net (optional)

Enables networking.

You can use the pre-built libraries in SDL_net-devel-1.2.8-VC.zip.

  • Library files:
    • SDL_net-1.2.8\lib\x86\SDL_net.dll
    • SDL_net-1.2.8\lib\x86\SDL_net.lib
  • Include folder:
    • SDL_net-1.2.8\include

SDL_sound (optional)

Enables the use of CD images with compressed audio.

  • Guide not yet written.

PDCurses (optional)

Enables a DOS debugger.

  • Guide not yet written.

Get DOSBox Source

Build DOSBox

  • After downloading the source code, open the Visual Studio solution: dosbox\visualc_net\dosbox.sln
  • Allow it to automatically convert to the latest version.
  • Right click the dosbox project in the Solution Explorer and open its Properties.
    • When editing the properties, edits will have to be made for each configuration you may want to build. In the top left there is an option for Debug, Release and All Configurations. The Release build is most commonly used, but All Configurations will let you conveniently edit both at once wherever the two configurations have the same options.
    • Click the drop down triangle on Configuration Properties > C/C++ > General > Additional Include Directories and edit this list. Add the appropriate include path for each library prepared above. Keep in mind that paths are relative to the dosbox\visualc_net folder.
    • Edit Configuration Properties > Linker > General > Additional Library Directories and add the path to each library (.lib) file prepared above.
    • Edit Configuration Properties > Linker > Input > Additional Dependencies to add or remove libraries. (You will have to select either the Debug or Release configuration for this, as the Debug build uses a different list of libraries than the Release.)
      • Remove zlib.lib and libpng.lib if not using these. Rename libpng.lib as libpng16.lib if you are using it.
      • Remove sdl_net.lib if not using it.
      • Add an entry for SDL_sound if using it.
      • Remove curses.lib if not using it.
  • Find dosbox\src\platform\visualc\config.h and open it (in the solution explorer it is under dosbox \ Source Files \ visualc).
    • C_SSHOT to 0 if not using zlib/libpng.
    • C_MODEM and C_IPX to 0 if not using SDL_net.
    • Add #define C_SDL_SOUND if using SDL_sound.
    • C_DEBUG to 1 if using the PDCurses.
  • After all of this is set up, you may build the dosbox project. Choose a Debug or Release configuration (recommend: Release) and use the build menu to build the solution. One of the following will be built:
    • dosbox\visualc_net\Release\dosbox.exe
    • dosbox\visualc_net\Debug\dosbox.exe
  • Finally, take the SDL.dll and SDL_net.dll files prepared above and place them in the same directory as dosbox.exe. It should now be ready to run.

Notes

  • When debugging with Visual Studio, breakpoints currently cause the host computer to slow to a crawl, making the debugger very difficult to use. Until a solution for this is found, you may wish to resort to "printf debugging" as a workaround, or alternatively consider building with MinGW and using GDB to debug. (discussion)