Difference between revisions of "Compiling ScummVM/Visual Studio"

From ScummVM :: Wiki
Jump to navigation Jump to search
(66 intermediate revisions by 9 users not shown)
Line 1: Line 1:
== Compiling ScummVM with Visual Studio 2003/2005 under Windows ==
== Compiling ScummVM with Visual Studio under Windows ==
 
 
Compiling ScummVM under Windows is not an awfully hard task, however there are some things that don't just work out of the box


Compiling ScummVM with Visual Studio is not an awfully hard task. It is however slightly more complicated than using MinGW. We guide you through the steps to make ScummVM compile with Visual Studio on this page.


== Things needed ==
== Things needed ==
Visual Studio 2008-2019


=== Visual Studio 2005 ===
=== Visual Studio ===
There exist several versions of Visual Studio 2005. A feature comparison can be found
There exists a free Community version of Visual Studio [https://visualstudio.microsoft.com/ here] that can be used.
[http://msdn.microsoft.com/vstudio/products/compare/default.aspx here]
Professional Visual Studioversions are working fine too.
 
You can obtain the free Express version of VS2005 [http://msdn.microsoft.com/vstudio/express/default.aspx here]
 
 
=== Precompiled libraries ===
To ease the whole process, a package of all the needed precompiled libraries has been created.
All you need to do is:
* [http://www.freefilehoster.com/uploads/1176748510vs2005_libs.zip Download the precompiled libraries]
* Unzip the archive maintaining directory structure
* Run install.bat (Visual Studio 2005 only)
* You don't need to add the libraries to Visual Studio, as the installer automatically copies the necessary files in the appropriate directories of Visual Studio. Please note that this installer has only been tested with Visual Studio 2005. If you get errors with earlier versions of Visual Studio, simply copy the directories ''bin'', ''lib'' and ''include'' inside the directory where Visual C++ is installed. If you're not sure how to do that, check the section "[[Compiling_ScummVM/VS2005#Adding_all_libraries_to_Visual_Studio|Adding all libraries to Visual Studio]]" further on
* Skip to step "[[Compiling_ScummVM/VS2005#Before_compiling|Before compiling]]"
 
 
=== Libraries needed ===
 
* [http://www.libsdl.org/download-1.2.php SDL 1.2].
You need the file SDL-devel-1.2.11-VC6.zip (1.2.11 is the latest version at this time)
 
* [http://www.kernel.org/pub/software/devel/nasm/binaries/win32/ NASM]
 
* [http://downloads.xiph.org/releases/ogg/ libogg] and [http://downloads.xiph.org/releases/vorbis/ libvorbis] for OGG support
 
Note that the libraries included in the "vorbis" package won't work. You need libogg and libvorbis, not vorbis
 
* [ftp://ftp.mars.org/pub/mpeg/ libmad] for MP3 support
 
* [http://libmpeg2.sourceforge.net/downloads.html libmpeg2] for MPEG-2 support
 
Get the latest mpeg2dec release from this page, libmpeg2 is included there
 
* [http://www.zlib.net/ zlib]. You need the latest zlib compiled DLL
 
If you wish to compile zlib statically in ScummVM (so that zlib1.dll is not needed), you'll also need the zlib source code. If you wish to compile ScummVM 0.8.0 or earlier with zlib support, you'll need the zlib source as well as [http://www.winimage.com/zLibDll/crtdll.zip crtdll.lib].
 
 
== Building the libraries ==
 
Now, we need to compile the required libraries.
 
Note that you'll need to build all libraries with the same configuration settings (debug or release). If you don't need a specific library, you can remove it from your build by going to Project->Properties, Configuration Properties->C/C++->Preprocessor and remove the "USE_XXX" directive for that library from there. For example, to remove OGG support, remove the USE_VORBIS directive
 
 
=== A note about VS2005 ===
 
If you're building the libraries with VS2005, you will get a lot of deprecation warnings. These are normal and nothing to worry about, they're just Microsoft's way of saying "This is a bad code practice. Use this instead". It's not easy to turn these off without several modifications to the code, so just ignore them.
 
Read more here:
 
http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/
 
http://www.gamedev.net/community/forums/topic.asp?topic_id=361433
 
http://blogs.msdn.com/oldnewthing/archive/2005/01/07/348437.aspx
 
If you do wish to make them disappear, you need to include on top the main function of each library, before the includes, the following lines:
 
  #if (_MSC_VER >= 1400) /* VC8+ (VS2005) */
  #pragma warning(disable : 4996) /* Disable all deprecation warnings */
  #endif /* VC8+ (VS2005) */
 
 
=== NASM ===
 
First of all, we need nasm. So unzip the nasm archive in a directory, copy
"nasmw.exe" to "nasm.exe" (because some projects call one and others call the other) and include it in the executable path of VS. To do this, go to Tools->Options->Projects and solutions->VC++ directories. Select "Executable files" from the top right and include the directory where you unzipped nasm into.
 
 
=== SDL ===
 
SDL is already compiled and needs no further changes, so we can skip the compilation step for it
 
 
=== zlib ===
 
zlib is already compiled, so we can skip the compilation step for it
 
 
If you wish to compile zlib statically into ScummVM (and thus, remove the zlib1.dll dependency), you'll also need the zlib source. Go into the projects directory in the zlib source and open the solution there. For each of the 3 projects in the solution (example, minigzip and zlib) you need to right-click it in the solution explorer and go to properties. Then, go to Configuration Properties->C/C++->Code Generation and change the Runtime library from "Multi-Threaded DLL (/MD)" to "Multi-Threaded (/MT)", otherwise you'll get a lot of unresolved externals when you try to build ScummVM and the compilation will fail. When you've changed all three projects, compile the solution using the LIB release configuration. Then, open the ScummVM solution and go to Project->Properties, Linker->Input and change the "zldll.lib" directive to "zlib.lib".
 
 
For ScummVM 0.8.0 or earlier, you'll also need zlibwapi. Go in the contrib\vstudio\vs8 directory (or vs7 if you're using VS2003), unzip crtdll.lib from the zip you downloaded earlier in the directory and compile zlibvc. This is a required library up to the stable 0.8.0 release, but it's not required anymore in the latest CVS version
 
 
=== libogg ===
 
Compile this first, as many other libraries need it. Go to the win32 directory and build the ogg solution in there. DON'T compile the solution in the VS2003 directory, as this produces "libogg.lib" instead of "ogg.lib". A simple rename might work, though
 
 
=== libvorbis ===
 
Before compiling this, include the libogg include and library paths in VS. To do this, go to Tools->Options->Projects and solutions->VC++ directories and include the include directory of libogg as well as the directory with the compiled ogg library
 
 
=== mpeg2dec ===
 
After you compile this one, go to its include directory, create a folder "mpeg2dec" in there and copy all files from the include folder in this subfolder. So you should end up with 2 directories, "include" and "include\mpeg2dec" with the same files. This is needed, as ScummVM includes files from the "mpeg2dec" directory
 
 
=== libmad ===
 
To compile this, you need to remove all the "_CRTRESTRICT" directives from the code, as VS doesn't understand this directive
 
 
=== FLAC ===
 
Not a necessary library, so you may skip this one. If you do wish to include it, open its solution and compile the libFLAC_static project.
 
 
== Adding all libraries to Visual Studio ==
 
There are two ways of adding the libraries to Visual Studio. You can either copy all the header and library files inside the appropriate directories of Visual C++ or tell Visual C++ where to look for them.
<br><br>
 
=== First method: Copy the files inside VC++'s folders ===
The '''first method''' of adding the required libraries is to go to each individual compiled library and copy the header and library files.
 
You'll need the following:<br><br>
'''Libraries'''<br>
  '''libFLAC_static.lib''' - static build of libFLAC (from folder obj\release\lib where you unzipped libFLAC)
  '''libmad.lib''' - static build of libMAD (from folder msvc++\Release where you unzipped libmad)
  '''libmpeg2.lib''' - static build of libMPEG2 (from folder vc++\Release where you unzipped mpeg2dec)
  '''ogg_static.lib''' - static build of libOGG (from folder win32\Static_Release where you unzipped libogg)
  '''sdl.lib''' - static build of SDL (from folder lib where you unzipped SDL)
  '''vorbisfile_static.lib''' - static build of vorbisfile (from folder win32\VorbisFile_Static_Release where you unzipped libvorbis)
  '''vorbis_static.lib''' - static build of libvorbis (from folder win32\Vorbis_Static_Release where you unzipped libvorbis)
  '''zlib.lib''' - static build of zlib (from folder projects\visualc6\Win32_LIB_Release where you unzipped zlib)
 
Copy those inside VC's lib folder (e.g. C:\Program Files\Microsoft Visual Studio 8\VC\lib)
<br><br>
'''Header files'''<br>
  [TODO]


Copy those inside VC's include folder (e.g. C:\Program Files\Microsoft Visual Studio 8\VC\include)
We do support older versions of Visual Studio too. However, on this page we focus on building ScummVM with Visual Studio. Building ScummVM with older Visual Studio 2008 can require additional work not described on this page.
<br><br>
'''Executable files'''<br>
  '''nasmw.exe''' - from the NASM zip


Copy this as nasmw.exe AND as nasm.exe inside VC's bin folder (e.g. C:\Program Files\Microsoft Visual Studio 8\VC\bin)
=== Needed Libraries ===
<br><br>
ScummVM relies on third-party libraries to implement certain functionality. Some of these libraries are required, like for example SDL, others are optional, like for example libtheora. We supply a set of prebuilt libraries for Visual Studio 2015. These have been build on Windows 8.1 using the Visual Studio 2015 Community Edition. The libraries can be found [http://www.scummvm.org/frs/build/scummvm_libs_2015.zip here].


=== Second method: Tell VC++ where to look ===
=== Installing Libraries ===
The '''second method''' is to tell VC++ where to look for the required libraries and header files
The easiest way to make Visual Studio find the supplied libraries is by using the environment variable "SCUMMVM_LIBS". We describe this method now.
To make it work you have to follow these steps:
* Unzip the library zip to a directory of your choice. For example, you can unzip them into "C:\Users\YourUsername\Documents\scummvm_libs_2015".
* Go to Control Panel -> Environment Variables and set up a new variable "SCUMMVM_LIBS" with a value of the path you extracted the zip in. It is important that you do point the variable to the folder containing the "bin", "include", and "lib" directories.


Go to Tools->Options->Projects and solutions->VC++ directories.  
=== Manually Building Libraries ===
If you want to build libraries for use with Visual Studio yourself, please refer to the [[Compiling_ScummVM/Visual_Studio/Compiling_Libraries|instructions for compiling the libraries yourself]].


In the executable files section, make sure that the path to nasm is included and that nasmw.exe in that folder has been copied to nasm.exe. Failure to do that will give you an error in VS (a custom building step has returned an error)
== Preparing the Project Files ==


In the include files section, make sure that the include folders for libogg, libvorbis, libmad, zlib, mpeg2dec and SDL are in the list. If you need FLAC, include the FLAC include folder in the list too
=== Building create_project ===


In the library files section, make sure that the static libraries for vorbis, vorbisfile, libogg, zlib, mpeg2dec, libmad and SDL are included. If you're building 0.8.0 final or earlier, include the release folder of zlibdll too (in the zlib source folder, contrib\vstudio\vc8\x86\zlibdllrelease). If you need FLAC, include the FLAC libraries folder too
ScummVM uses a configure/Make based build system. We have a tool to generate Visual Studio project files from this build system. The first steep you need to take is building this tool called "create_project".


Finally, if you need to compile ScummVM with FLAC support, go to Configuration Properties->C/C++->Preprocessor and add "USE_FLAC" in the Preprocessor Definitions field. Also, go to linker->input and add "libflac_static.lib" in the Additional Dependencies field.
First, open the solution file "devtools\create_project\msvc\create_project.sln". Then simply build the solution. The project file should automatically assure that the resulting "create_project.exe" is copied to "dists\msvc". If not, you will have to copy it yourself.


=== Generating the Project Files ===


== Before compiling ==
Simply run the batch script "dists/msvc/create_msvc.bat". It will guide you through configuring ScummVM.


Open the solution file in dists\vc8 (or vc7 if you're using VS2003)
'''IMPORTANT''': You will have to re-generate the project files whenever new source files have been added to or removed from the configure/Make based build system. When you add new files to ScummVM, you will ''have'' to add them to the respective "module.mk" file to assure ScummVM still builds fine with the configure/Make based build system.


Before compiling, open the file sound\softsynth\ym2612.cpp in the scummvm directory with VS and save it as unicode. To do this, go to File->Save as and in the save button, click the small arrow next to it and select "Save with encoding" and select "UTF8" from the list. The reason for this step is that this file contains Japanese characters, so VS refuses to compile the project if it's not saved as unicode
== Compiling ScummVM ==


After compiling, don't forget to copy "sdl.dll" in the release and debug directories where scummvm.exe is located. If you haven't compiled zlib statically into ScummVM and have included zlib support, you'll need to copy "zlib1.dll" in the same directory as scummvm.exe as well
If you followed all the steps, you are now ready to compile ScummVM with Visual Studio. Congratulations!


Simply open the generated solution file in "dists\msvc\scummvm.sln". Now you can ask it to build the desired configuration. By default it will build a debug configuration which is ideal to hack on ScummVM.


== Ready to go! ==
'''IMPORTANT''': You'll need to copy the matching SDL.dll file to a location Windows picks up to run the resulting binary. The easiest way to do this is to place the SDL.dll file in the directory where scummvm.exe is. There are multiple SDL.dll files to choose from, depending on your build configuration. Simply pick the right one from the prebuilt libraries. For example, if you build a Win32 Debug configuration, you will need to use "libs/x86/Debug/SDL.dll".


OK this should be all of it (thankfully), so you should be good to go.
== Compiling without Console/Status Window ==


Note that whenever you get a new release from the scummvm website, you need to follow the steps in the "before compiling" section to compile scummvm
If you want to run ScummVM without the console Window being present by default, there are two things you need to do:
* In the Project Options for the scummvm project, go to the Linker | System | SubSystem line, and change the /SUBSYSTEM:CONSOLE to /SUBSYSTEM:WINDOWS
* In the file backends/platform/sdl/win32/win32.cpp, change the parameter from true to false in the first line of OSystem_Win32::initBackend:
ConfMan.registerDefault("console", false);

Revision as of 11:51, 20 April 2019

Compiling ScummVM with Visual Studio under Windows

Compiling ScummVM with Visual Studio is not an awfully hard task. It is however slightly more complicated than using MinGW. We guide you through the steps to make ScummVM compile with Visual Studio on this page.

Things needed

Visual Studio 2008-2019

Visual Studio

There exists a free Community version of Visual Studio here that can be used. Professional Visual Studioversions are working fine too.

We do support older versions of Visual Studio too. However, on this page we focus on building ScummVM with Visual Studio. Building ScummVM with older Visual Studio 2008 can require additional work not described on this page.

Needed Libraries

ScummVM relies on third-party libraries to implement certain functionality. Some of these libraries are required, like for example SDL, others are optional, like for example libtheora. We supply a set of prebuilt libraries for Visual Studio 2015. These have been build on Windows 8.1 using the Visual Studio 2015 Community Edition. The libraries can be found here.

Installing Libraries

The easiest way to make Visual Studio find the supplied libraries is by using the environment variable "SCUMMVM_LIBS". We describe this method now. To make it work you have to follow these steps:

  • Unzip the library zip to a directory of your choice. For example, you can unzip them into "C:\Users\YourUsername\Documents\scummvm_libs_2015".
  • Go to Control Panel -> Environment Variables and set up a new variable "SCUMMVM_LIBS" with a value of the path you extracted the zip in. It is important that you do point the variable to the folder containing the "bin", "include", and "lib" directories.

Manually Building Libraries

If you want to build libraries for use with Visual Studio yourself, please refer to the instructions for compiling the libraries yourself.

Preparing the Project Files

Building create_project

ScummVM uses a configure/Make based build system. We have a tool to generate Visual Studio project files from this build system. The first steep you need to take is building this tool called "create_project".

First, open the solution file "devtools\create_project\msvc\create_project.sln". Then simply build the solution. The project file should automatically assure that the resulting "create_project.exe" is copied to "dists\msvc". If not, you will have to copy it yourself.

Generating the Project Files

Simply run the batch script "dists/msvc/create_msvc.bat". It will guide you through configuring ScummVM.

IMPORTANT: You will have to re-generate the project files whenever new source files have been added to or removed from the configure/Make based build system. When you add new files to ScummVM, you will have to add them to the respective "module.mk" file to assure ScummVM still builds fine with the configure/Make based build system.

Compiling ScummVM

If you followed all the steps, you are now ready to compile ScummVM with Visual Studio. Congratulations!

Simply open the generated solution file in "dists\msvc\scummvm.sln". Now you can ask it to build the desired configuration. By default it will build a debug configuration which is ideal to hack on ScummVM.

IMPORTANT: You'll need to copy the matching SDL.dll file to a location Windows picks up to run the resulting binary. The easiest way to do this is to place the SDL.dll file in the directory where scummvm.exe is. There are multiple SDL.dll files to choose from, depending on your build configuration. Simply pick the right one from the prebuilt libraries. For example, if you build a Win32 Debug configuration, you will need to use "libs/x86/Debug/SDL.dll".

Compiling without Console/Status Window

If you want to run ScummVM without the console Window being present by default, there are two things you need to do:

  • In the Project Options for the scummvm project, go to the Linker | System | SubSystem line, and change the /SUBSYSTEM:CONSOLE to /SUBSYSTEM:WINDOWS
  • In the file backends/platform/sdl/win32/win32.cpp, change the parameter from true to false in the first line of OSystem_Win32::initBackend:
ConfMan.registerDefault("console", false);