Building MAME using Microsoft Visual Studio compilers: Difference between revisions

From MAMEDEV Wiki
m (fix link markup)
(Updated Page for Version change to Visual Studio 2017)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
By default, MAME is configured via the makefile to build using the MinGW gcc compiler. Although this is a nice cross-platform solution, debugging binaries built this way leaves a lot to be desired.
By default, MAME is configured via the makefile to build using the MinGW gcc compiler. Although this is a nice cross-platform solution, debugging binaries built this way leaves a lot to be desired.


If you own a copy of Visual Studio .NET 2003 or Visual Studio 2005, you can configure MAME to build using those tools instead. Once you have done that, you can debug problems in MAME using the Visual Studio debugger, which is a huge step up from gdb.
Alternatively, you can configure MAME to build using Visual Studio. Once you have done that, you can debug problems in MAME using the Visual Studio debugger, which is a huge step up from gdb.
 
Since MAME uses modern C++ features, Visual Studio 2017 is required. MAME previously used Visual Studio 2015, but it has updated to the newer version as of August 2018. If you don't have a paid license, [https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx Visual Studio Community 2017] is available from Microsoft for free (but requires sign-in with a Microsoft account).
 
'''Additional Note on VS 2017 Versions''' - There is an issue compiling with certain versions of Visual Studio 2017. Currently it is advised to use Visual Studio 2017 version 15.7.6. Later versions will not compile successfully and Microsoft has said that this will not be fixed until version 16.X.X.  


Here's how to make it work:
Here's how to make it work:


# You must already have an environment that can build MAME using the MinGW tools. Although you won't be using gcc to compile, you will be using several of the other tools included in the standard MAME [http://mamedev.org/tools/ MinGW Development Environment]
# You must already have an environment that can build MAME using the MinGW tools. Although you won't be using gcc to compile, you will be using several of the other tools included in the standard MAME [http://mamedev.org/tools/ MinGW Development Environment]
# From the command prompt, you need to run the batch file that was installed with Visual Studio which configures the executable, include, and library paths.
#* For Visual Studio .NET 2003, the command is: (can't remember)
#* For Visual Studio 2005, the command is: <code>"\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86</code>
#** (To build a 64-bit version, change the <code>x86</code> to <code>amd64</code>)
# Switch to the directory where the root MAME makefile lives.
# Switch to the directory where the root MAME makefile lives.
# Delete any object files from previous builds using gcc: <code>rd /s obj</code>
# Once you've done that, simply run: <code>make vs2017 PYTHON_EXECUTABLE=c:/msys64/mingw64/bin/python.exe</code> and wait for it to create projects
# Once you've done that, simply run: <code>mingw32-make MSVC_BUILD=1 DEBUG=1 SYMBOLS=1</code> and wait for it to complete (I suggest building with DEBUG=1 as that also disables optimizations and makes debugging much easier).
# In order not to specify PYTHON_EXECUTABLE all the time, just place it in system variables
#* (To build a 64-bit version, add <code>PTR64=1</code> to the end of your command line.)
# If you are building with XP compatibility enabled run  <code>make vs2017_xp</code>
 
# Browse to folder containing solution file and open it with Visual Studio
At this point, you should now have a mamed.exe that was built using Visual Studio tools. To debug it is very easy.
# Inside Visual Studio you can change to Debug/Release x86 or x64 builds
 
# While doing development please note that you need to update LUA files in scripts folders in order to add new sources and regenerate projects
# Open up Visual Studio.
# Note that all parameters for partial compilation works so you can do <code>make SUBTARGET=tiny vs2017</code> or <code>make vs2017 SUBTARGET=drivername SOURCES=src\mame\drivers\drivername.cpp</code>
# From the File menu choose "Open Project..."
# Select mamed.exe (you may need to adjust the file filters to show .exe files).
# To configure command line parameters, right click on the mamed.exe item in the Solution Explorer window and choose "Properties". In that window you can specify the "Command Arguments" which would be the command line parameters you want.
# Set some breakpoints if you want, and hit "Go" (F5), or else single step into main by hitting "Step Into" (F11).
# When you're done, Visual Studio will ask if you want to save a solution file (.sln); I usually say "yes", because then it will remember your last session parameters for the next time you want to debug MAME, and the solution will show up in the recent projects list.
 
Back to [[How MAME Works]]
Back to [[How MAME Works]]

Latest revision as of 20:31, 2 December 2018

By default, MAME is configured via the makefile to build using the MinGW gcc compiler. Although this is a nice cross-platform solution, debugging binaries built this way leaves a lot to be desired.

Alternatively, you can configure MAME to build using Visual Studio. Once you have done that, you can debug problems in MAME using the Visual Studio debugger, which is a huge step up from gdb.

Since MAME uses modern C++ features, Visual Studio 2017 is required. MAME previously used Visual Studio 2015, but it has updated to the newer version as of August 2018. If you don't have a paid license, Visual Studio Community 2017 is available from Microsoft for free (but requires sign-in with a Microsoft account).

Additional Note on VS 2017 Versions - There is an issue compiling with certain versions of Visual Studio 2017. Currently it is advised to use Visual Studio 2017 version 15.7.6. Later versions will not compile successfully and Microsoft has said that this will not be fixed until version 16.X.X.

Here's how to make it work:

  1. You must already have an environment that can build MAME using the MinGW tools. Although you won't be using gcc to compile, you will be using several of the other tools included in the standard MAME MinGW Development Environment
  2. Switch to the directory where the root MAME makefile lives.
  3. Once you've done that, simply run: make vs2017 PYTHON_EXECUTABLE=c:/msys64/mingw64/bin/python.exe and wait for it to create projects
  4. In order not to specify PYTHON_EXECUTABLE all the time, just place it in system variables
  5. If you are building with XP compatibility enabled run make vs2017_xp
  6. Browse to folder containing solution file and open it with Visual Studio
  7. Inside Visual Studio you can change to Debug/Release x86 or x64 builds
  8. While doing development please note that you need to update LUA files in scripts folders in order to add new sources and regenerate projects
  9. Note that all parameters for partial compilation works so you can do make SUBTARGET=tiny vs2017 or make vs2017 SUBTARGET=drivername SOURCES=src\mame\drivers\drivername.cpp

Back to How MAME Works