Difference between revisions of "Building DOSBox with MinGW"

From DOSBoxWiki
Jump to navigationJump to search
m (→‎Compiling DOSBox: that last line is another step)
 
(55 intermediate revisions by 17 users not shown)
Line 1: Line 1:
As nobody has yet ported the original page (http://dosbox.sourceforge.net/wiki/index.php?page=BuildingDOSBox) I've done it.
+
DOSBox is a complicated project. This document aims to provide a step by step description of how to use the MinGW developement environment to successfully build DOSBox. An alternative is to use [[Building DOSBox with Visual Studio|Microsoft Visual Studio]].
<br><br>
+
 
<br><br>
+
This page will guide you through setting up MinGW to compile a current (SVN/CVS) version of DOSBox. Because of updates to compilers and libraries, this guide will not work with the 0.74 (the last official release, which is currently over 6 years old) source files.
<br>Building your own version of DOSBox
+
 
<br>1. Grab the source
+
An alternative guide is also available on the forums: https://www.vogons.org/viewtopic.php?f=31&t=55706
<br>
+
 
<br>First, grab the latest version of the DOSbox sourcecode. A fairly often updated CVS-Dump can be found at: http://dosbox.linuxdevel.net/dosboxcvs.tgz
+
Additional build setup notes may be found in the latest '''INSTALL''' file: https://sourceforge.net/p/dosbox/code-0/HEAD/tree/dosbox/trunk/INSTALL
<br>
+
 
<br>Download it and extract it to a seperate directory.
+
== Installing MinGW ==
<br>2. SDL
+
* Download mingw-get-setup.exe from http://sourceforge.net/projects/mingw/
<br>
+
* Run the installer, choosing the defaults
<br>DOSBox utilizes SDL (Simple DirectMedia Layer) to use your graphics and sound-hardware. Ergo, you'll need to download it as well. Grab the latest source at
+
* Once the '''MinGW Installation Manager''' application starts, select
<br>http://www.libsdl.org/
+
** mingw-developer-toolkit (msys-base should be automatically added)
<br>
+
** mingw32-base
<br>and extract to a seperate directory.
+
** mingw32-gcc-g++
<br>
+
* On the installation menu, apply changes, and confirm that you want to apply the changes
<br>When working on Windows, you might want to save a lot of effort and just use the SDL (and optionally SDL_net) .DLL files included with the latest official DOSBox release, as compiling SDL with full options (e.g. DirectX support) is a bit involved. There are also pre-built .DLL files on the SDL web site (Runtime Libraries -> Win32) that you can try at
+
 
<br>http://www.libsdl.org/download-1.2.php
+
The installation manager is going to download a bunch of files, and at the end, start installing them. Once this is done, you can close the dialog box as well as the installation manager.
<br>
+
 
<br>Note that as of 12 Dec 2004, ddraw (DirectDraw) rendering mode will not work in DOSBox unless you either use the SDL.dll included with the latest version of DOSBox, or build your own SDL.dll with the changes mentioned in the "Compiling SDL" section below.
+
Well done, MinGW is now installed! Let's start it up.
<br>3. Compiling enviroment
+
 
<br>
+
* Browse to '''C:\MinGW\msys\1.0'''
<br>When working on Windows, you'll most likely need a compiling enviroment. We suggest using the combination of MiniGW and MSYS, which can be found at
+
* Run '''MSYS.BAT'''
<br>http://prdownloads.sf.net/mingw/
+
 
<br>
+
This will start up a DOS prompt like screen, lets mount the base path
<br>You'll need to download both the latest MiniGW and MSYS. After downloading install MiniGW and MSYS (in this order). The MSYS-Installer should ask for the installation directory of MiniGW, so you should pick the path where you installed it. After the installation, run the MSYS.BAT and you should see a unix-like command prompt.  
+
  mount 'c:\MinGW' /mingw
<br>4. Compiling SDL
+
 
<br>
+
You have now completed this section, lets move on to adding the SDL libraries to MinGW.
<br>Navigate to the directory where you extracted the SDL-source (using unix commands) and type
+
 
<br>./configure
+
== Adding the SDL libraries to MinGW ==
<br>make
+
* Download the pre compiled SDL development libraries from here http://www.libsdl.org/release/SDL-devel-1.2.15-mingw32.tar.gz
<br>make install
+
* Copy the downloaded file to your MSYS home folder, it's going to be something like '''C:\MinGW\msys\1.0\home\Administrator'''
<br>
+
* Switch back to the MSYS command prompt we started earlier
<br>Some MinGW-specific info on compiling SDL under Windows is available at
+
* Lets extract the downloaded files
<br>http://www.libsdl.org/extras/win32/mingw32/README.txt
+
  tar xvf SDL-devel-1.2.15-mingw32.tar.gz
<br>
+
* And now add the files to MinGW
<br>If you are having trouble with a message like 'no acceptable ld found in $PATH' try 'export LD=/c/gxx-2.95.2/bin/ld.exe' (or wherever you have the exe; GCC 2.95 in this case)
+
  cd SDL-1.2.15
<br>
+
  make install-sdl prefix=/mingw
<br>Also, if you have trouble getting ddraw (DirectDraw) working in DOSBox, see this post on the DOSBox forum for a possible fix:
+
  cd ..
<br>http://vogons.zetafleet.com/viewtopic.php?p=48050&highlight=#48050
+
 
<br>4b. SDL-net (optional)
+
Cool, the SDL libraries have been added to MinGW, onto the next section.
<br>
+
 
<br>If you want to benefit from DOSBox'es Modem-Emulation or IPX-Support, you'll additionally need the SDL-net library, which can be found at
+
== Adding Direct Draw support to DOSBox (Optional) ==
<br>http://www.libsdl.org/projects/SDL_net/
+
If you want to give DOSBox the option to use the DDRAW output option, then we need to add a couple of extra libraries to MinGW
<br>
+
* Download the following file, http://www.libsdl.org/extras/win32/common/directx-devel.tar.gz
<br>Download, extract and compile as you did with SDL.
+
* Copy the downloaded file to your MSYS home folder
<br>
+
* Switch to the MSYS command prompt
<br>If you skipped building your own SDL.dll, you can use the one included with the latest official release of DOSBox or you can get a SDL_net win32 binary (.DLL) release on the SDL web site at the URL above.
+
* Extract the files (the -C parameter, tells tar where to extract the files to)
<br>5. Compiling DOSBox
+
  tar xvf directx-devel.tar.gz -C /mingw
<br>
+
 
<br>After compiling you'll need to adjust the PATH variable to point at the directory where the freshly built SDL-Library can be found.
+
== Adding networking support to DOSBox (Optional) ==
<br>
+
These steps show you how to add the SDL_net libraries to MinGW, which enable networking and modem for DOSBox. If you aren't going to be using DOSBox for multi player games, then you can probably skip this step.
<br>Note: if you want to use SDL-net, do the same with that library.
+
* Download the SDL_net source files from https://www.libsdl.org/projects/SDL_net/release/SDL_net-1.2.8.tar.gz
<br>
+
* Copy the downloaded file to your MSYS home folder
<br>Then, change to the directory where you extracted the DOSBox-Source and type
+
* Switch to the MSYS command prompt
<br>./configure
+
* Extract the file
<br>make
+
  tar xvf SDL_net-1.2.8.tar.gz
<br>
+
* Lets configure the libraries
<br>to compile DOSBox. If everything worked, you should have a DOSBOX.EXE in the ./src - directory.
+
  cd SDL_net-1.2.8
<br>6. Running
+
  ./configure --prefix=/mingw
<br>
+
* '''SDLnet.c''' will have to be modified slightly to compile. Open it with a text editor and add the following #include near the top of the file:
<br>The easiest way to run the new executable is to copy it (and your fresh SDL.dll and maybe even the SDL_net.dll) to the installation-directory of a non-CVS-version of DOSBox. That way, you have the needed directory structure and configuration files.
+
  #include <winerror.h>
<br>Example for Building DosBOX 7.1 on OpenSUSE 10.2 Linux
+
* And now compile them
<br>
+
  make
<br>NOTE: configure flags need double dashes in front of them. Couldn't show this due to wiki formatting restrictions.
+
* And then install them (copy the files)
<br>
+
  make install
<br>-Remove the existing dosbox version if you have it.
+
  cd ..
<br>
+
 
<br>-Obtain and extract the dosbox source code.
+
== Adding screenshot support (Optional) ==
<br>
+
This one is a bit tricky because it relies on two libraries, zlib (libpng needs these libraries), and libpng. We are also going to be compiling the libraries statically to keep external DLL's to a minimum.
<br>-SUSE linux 10.2 already has SDL and alsa installed, but you need to install the SDL-devel package and alsa-devel package (for header files and libs).
+
* Download zlib from here http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.xz/download
<br>
+
* Copy the downloaded file to your MSYS home folder
<br>-Obtain the SDL_Sound src from http://icculus.org/SDL_sound/downloads. Extract the source somewhere.
+
* Switch to the MSYS command prompt
<br>
+
* Extract the file
<br>Run configure -with-sdl-prefix=/usr/lib64 -with-sdl-exec-prefix=/usr
+
  tar xvf zlib-1.2.8.tar.xz
<br>
+
* Lets build the static library
<br>make
+
  cd zlib-1.2.8
<br>
+
  make -f win32/Makefile.gcc
<br>make install (need to be root)
+
* And now copy the files to /mingw
<br>
+
  cp libz.a /mingw/lib/
<br>-OK, now you have everything you need to compile dosbox. cd to your dosbox directory, then run this at the shell:
+
  cp zlib.h zconf.h /mingw/include/
<br>
+
  cd ..
<br>export CPPFLAGS="-I/usr/local/include/SDL"
+
Cool, that wasn't too hard, onto libpng
<br>
+
* Download libpng from here https://sourceforge.net/projects/libpng/files/libpng16/older-releases/1.6.18/libpng-1.6.18.tar.xz/download
<br>export LDFLAGS="-L/usr/local/lib"
+
* Copy the downloaded file to your MSYS home folder
<br>
+
* Switch to the MSYS command prompt
<br>configure -with-sdl-prefix=/usr/lib64 -with-sdl-exec-prefix=/usr -with-alsa-prefix=/usr/lib64
+
* Extract the file
<br>
+
  tar xvf libpng-1.6.18.tar.xz
<br>-with-alsa-inc-prefix=/usr/include/alsa
+
* Configure the library
<br>
+
  cd libpng-1.6.18
<br>make
+
  ./configure --disable-shared --prefix=/mingw
<br>
+
* There is currently [https://sourceforge.net/p/libpng/bugs/273/ a problem with the configure script] that will need to be manually resolved. Open '''pnglibconf.h''' with a text editor, and you will find several #define lines near the bottom that have been erroneously split into two lines. This can be fixed by adding a backslash to the end of the affected lines:
<br>make install (need to be root).
+
  199: #define PNG_TEXT_Z_DEFAULT_COMPRESSION \
<br>
+
  201: #define PNG_TEXT_Z_DEFAULT_STRATEGY \
<br>-The reason for the shell variables is that it seemed to be the only way configure could find the files it needed. There aren't any config options to find the SDL_sound library, and I tried giving it -libdir= and -includedir=, but that didn't work.
+
  209: #define PNG_ZLIB_VERNUM \
<br>
+
  211: #define PNG_Z_DEFAULT_COMPRESSION \
 +
  213: #define PNG_Z_DEFAULT_NOFILTER_STRATEGY \
 +
  215: #define PNG_Z_DEFAULT_STRATEGY \
 +
* And now to compile and install the files
 +
  make
 +
  make install
 +
  cd ..
 +
 
 +
== Adding support for compressed audio on diskimages (Optional) ==
 +
This is for cue/bin cdrom images with compressed (ogg) audio tracks. We will be adding the libvorbis, libogg, and sdl_sound libraries.
 +
* Download libogg from here http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
 +
* Copy the downloaded file to your MSYS home folder
 +
* Switch to the MSYS command prompt
 +
* Extract the file
 +
  tar xvf libogg-1.3.2.tar.gz
 +
* Configure the library, disabling shared library files
 +
  cd libogg-1.3.2
 +
  ./configure --disable-shared --prefix=/mingw
 +
* Compile and install the library files
 +
  make
 +
  make install
 +
  cd ..
 +
 
 +
* Download libvorbis from here http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
 +
* Copy the downloaded file to your MSYS home folder
 +
* Switch to the MSYS command prompt
 +
* Extract the file
 +
  tar xvf libvorbis-1.3.5.tar.gz
 +
* Configure the library, disabling shared library files
 +
  cd libvorbis-1.3.5
 +
  ./configure --disable-shared --prefix=/mingw
 +
* Compile and install the library files
 +
  make
 +
  make install
 +
  cd ..
 +
 
 +
* Download sdl_sound from here https://www.icculus.org/SDL_sound/downloads/SDL_sound-1.0.3.tar.gz
 +
* Copy the downloaded file to your MSYS home folder
 +
* Switch to the MSYS command prompt
 +
* Extract the file
 +
  tar xvf SDL_sound-1.0.3.tar.gz
 +
* Configure and compile
 +
  cd SDL_sound-1.0.3
 +
  ./configure --disable-shared --prefix=/mingw LIBS="-lvorbisfile -lvorbis -logg"
 +
  make
 +
  make install
 +
  cd ..
 +
 
 +
== Enabling the debugger (You probably don't want this) ==
 +
The debugger is mainly for developers of DOSBox, so they can find out why a game isn't working.
 +
* Download the PDCurses source files from http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/PDCurses-3.4.tar.gz
 +
* Copy the downloaded file to your MSYS home folder
 +
* Switch to the MSYS command prompt
 +
* Extract the file
 +
  tar xvf PDCurses-3.4.tar.gz
 +
* Compile the library
 +
  cd PDCurses-3.4/win32
 +
  make -f gccwin32.mak DLL=N
 +
* And now copy the files to your /mingw folders
 +
  cp pdcurses.a /mingw/lib/libpdcurses.a
 +
  cd ..
 +
  cp curses.h panel.h /mingw/include/
 +
  cd ..
 +
 
 +
== Compiling DOSBox ==
 +
* 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.
 +
 
 +
 
 +
* If using the snapshot, copy that file to your MSYS home folder, and extract the file
 +
  tar xvf dosboxsvn.tgz
 +
* Let's configure DOSBox, and tell it to use the static C library (-static-libgcc) and C++ library (-static-libstdc++) and stripping the final EXE of debug information (-s)
 +
  cd dosbox
 +
  ./autogen.sh
 +
  ./configure --enable-core-inline LDFLAGS="-static-libgcc -static-libstdc++ -s"
 +
* For SDL_sound support, you have to extra some extra parameters so that the configure command knows where to find the audio library files (LIBS="-lvorbisfile.....)
 +
  ./configure --enable-core-inline LDFLAGS="-static-libgcc -static-libstdc++ -s" LIBS="-lvorbisfile -lvorbis -logg"
 +
* If you want to enable debugging (you probably don't)
 +
  ./configure --enable-core-inline LDFLAGS="-static-libgcc -static-libstdc++ -s" LIBS="-lvorbisfile -lvorbis -logg" --enable-debug
 +
* And now for compiling DOSBox
 +
  make
 +
* The last step is to gather all the files together in a folder
 +
** Create a folder with a name of your choosing
 +
** Copy the dosbox.exe file located under the '''dosbox\src''' folder, e.g. '''C:\MinGW\msys\1.0\home\Administrator\dosbox\src''' to the folder you created
 +
** Copy the SDL.dll file located under '''SDL-1.2.15\bin''', e.g. '''C:\MinGW\msys\1.0\home\Administrator\SDL-1.2.15\bin''' to the folder you created
 +
** Optionally, copy the SDL_net.dll file located under '''SDL_net-1.2.8\.libs''', e.g. '''C:\MinGW\msys\1.0\home\Administrator\SDL_net-1.2.8\.libs''' to the folder you created
 +
 
 +
* Start up DOSBox, and see if it works!

Latest revision as of 00:37, 14 July 2018

DOSBox is a complicated project. This document aims to provide a step by step description of how to use the MinGW developement environment to successfully build DOSBox. An alternative is to use Microsoft Visual Studio.

This page will guide you through setting up MinGW to compile a current (SVN/CVS) version of DOSBox. Because of updates to compilers and libraries, this guide will not work with the 0.74 (the last official release, which is currently over 6 years old) source files.

An alternative guide is also available on the forums: https://www.vogons.org/viewtopic.php?f=31&t=55706

Additional build setup notes may be found in the latest INSTALL file: https://sourceforge.net/p/dosbox/code-0/HEAD/tree/dosbox/trunk/INSTALL

Installing MinGW

  • Download mingw-get-setup.exe from http://sourceforge.net/projects/mingw/
  • Run the installer, choosing the defaults
  • Once the MinGW Installation Manager application starts, select
    • mingw-developer-toolkit (msys-base should be automatically added)
    • mingw32-base
    • mingw32-gcc-g++
  • On the installation menu, apply changes, and confirm that you want to apply the changes

The installation manager is going to download a bunch of files, and at the end, start installing them. Once this is done, you can close the dialog box as well as the installation manager.

Well done, MinGW is now installed! Let's start it up.

  • Browse to C:\MinGW\msys\1.0
  • Run MSYS.BAT

This will start up a DOS prompt like screen, lets mount the base path

 mount 'c:\MinGW' /mingw

You have now completed this section, lets move on to adding the SDL libraries to MinGW.

Adding the SDL libraries to MinGW

  • Download the pre compiled SDL development libraries from here http://www.libsdl.org/release/SDL-devel-1.2.15-mingw32.tar.gz
  • Copy the downloaded file to your MSYS home folder, it's going to be something like C:\MinGW\msys\1.0\home\Administrator
  • Switch back to the MSYS command prompt we started earlier
  • Lets extract the downloaded files
 tar xvf SDL-devel-1.2.15-mingw32.tar.gz
  • And now add the files to MinGW
 cd SDL-1.2.15
 make install-sdl prefix=/mingw
 cd ..

Cool, the SDL libraries have been added to MinGW, onto the next section.

Adding Direct Draw support to DOSBox (Optional)

If you want to give DOSBox the option to use the DDRAW output option, then we need to add a couple of extra libraries to MinGW

 tar xvf directx-devel.tar.gz -C /mingw

Adding networking support to DOSBox (Optional)

These steps show you how to add the SDL_net libraries to MinGW, which enable networking and modem for DOSBox. If you aren't going to be using DOSBox for multi player games, then you can probably skip this step.

 tar xvf SDL_net-1.2.8.tar.gz
  • Lets configure the libraries
 cd SDL_net-1.2.8
 ./configure --prefix=/mingw
  • SDLnet.c will have to be modified slightly to compile. Open it with a text editor and add the following #include near the top of the file:
 #include <winerror.h>
  • And now compile them
 make
  • And then install them (copy the files)
 make install
 cd ..

Adding screenshot support (Optional)

This one is a bit tricky because it relies on two libraries, zlib (libpng needs these libraries), and libpng. We are also going to be compiling the libraries statically to keep external DLL's to a minimum.

 tar xvf zlib-1.2.8.tar.xz
  • Lets build the static library
 cd zlib-1.2.8
 make -f win32/Makefile.gcc
  • And now copy the files to /mingw
 cp libz.a /mingw/lib/
 cp zlib.h zconf.h /mingw/include/
 cd ..

Cool, that wasn't too hard, onto libpng

 tar xvf libpng-1.6.18.tar.xz
  • Configure the library
 cd libpng-1.6.18
 ./configure --disable-shared --prefix=/mingw
  • There is currently a problem with the configure script that will need to be manually resolved. Open pnglibconf.h with a text editor, and you will find several #define lines near the bottom that have been erroneously split into two lines. This can be fixed by adding a backslash to the end of the affected lines:
 199: #define PNG_TEXT_Z_DEFAULT_COMPRESSION \
 201: #define PNG_TEXT_Z_DEFAULT_STRATEGY \
 209: #define PNG_ZLIB_VERNUM \
 211: #define PNG_Z_DEFAULT_COMPRESSION \
 213: #define PNG_Z_DEFAULT_NOFILTER_STRATEGY \
 215: #define PNG_Z_DEFAULT_STRATEGY \
  • And now to compile and install the files
 make
 make install
 cd ..

Adding support for compressed audio on diskimages (Optional)

This is for cue/bin cdrom images with compressed (ogg) audio tracks. We will be adding the libvorbis, libogg, and sdl_sound libraries.

 tar xvf libogg-1.3.2.tar.gz
  • Configure the library, disabling shared library files
 cd libogg-1.3.2
 ./configure --disable-shared --prefix=/mingw
  • Compile and install the library files
 make
 make install
 cd ..
 tar xvf libvorbis-1.3.5.tar.gz
  • Configure the library, disabling shared library files
 cd libvorbis-1.3.5
 ./configure --disable-shared --prefix=/mingw
  • Compile and install the library files
 make
 make install
 cd ..
 tar xvf SDL_sound-1.0.3.tar.gz
  • Configure and compile
 cd SDL_sound-1.0.3
 ./configure --disable-shared --prefix=/mingw LIBS="-lvorbisfile -lvorbis -logg"
 make
 make install
 cd ..

Enabling the debugger (You probably don't want this)

The debugger is mainly for developers of DOSBox, so they can find out why a game isn't working.

 tar xvf PDCurses-3.4.tar.gz
  • Compile the library
 cd PDCurses-3.4/win32
 make -f gccwin32.mak DLL=N
  • And now copy the files to your /mingw folders
 cp pdcurses.a /mingw/lib/libpdcurses.a
 cd ..
 cp curses.h panel.h /mingw/include/
 cd ..

Compiling DOSBox


  • If using the snapshot, copy that file to your MSYS home folder, and extract the file
 tar xvf dosboxsvn.tgz
  • Let's configure DOSBox, and tell it to use the static C library (-static-libgcc) and C++ library (-static-libstdc++) and stripping the final EXE of debug information (-s)
 cd dosbox
 ./autogen.sh
 ./configure --enable-core-inline LDFLAGS="-static-libgcc -static-libstdc++ -s"
  • For SDL_sound support, you have to extra some extra parameters so that the configure command knows where to find the audio library files (LIBS="-lvorbisfile.....)
 ./configure --enable-core-inline LDFLAGS="-static-libgcc -static-libstdc++ -s" LIBS="-lvorbisfile -lvorbis -logg"
  • If you want to enable debugging (you probably don't)
 ./configure --enable-core-inline LDFLAGS="-static-libgcc -static-libstdc++ -s" LIBS="-lvorbisfile -lvorbis -logg" --enable-debug
  • And now for compiling DOSBox
 make
  • The last step is to gather all the files together in a folder
    • Create a folder with a name of your choosing
    • Copy the dosbox.exe file located under the dosbox\src folder, e.g. C:\MinGW\msys\1.0\home\Administrator\dosbox\src to the folder you created
    • Copy the SDL.dll file located under SDL-1.2.15\bin, e.g. C:\MinGW\msys\1.0\home\Administrator\SDL-1.2.15\bin to the folder you created
    • Optionally, copy the SDL_net.dll file located under SDL_net-1.2.8\.libs, e.g. C:\MinGW\msys\1.0\home\Administrator\SDL_net-1.2.8\.libs to the folder you created
  • Start up DOSBox, and see if it works!