Difference between revisions of "Compiling ScummVM/Visual Studio"

From ScummVM :: Wiki
Jump to navigation Jump to search
(→‎Generating the Project Files: Add info on using FluidLite instead of FluidSynth when using the prebuilt libraries)
 
(103 intermediate revisions by 15 users not shown)
Line 1: Line 1:
== Compiling ScummVM with Visual Studio 2003/2005 under Windows ==
== Installing the needed software and libraries ==


In this page, we guide you through the steps to compile ScummVM with Visual Studio.


Compiling ScummVM under Windows is not an awfully hard task, however there are some things that don't just work out of the box
=== Visual Studio ===
You can get the free Community version of Visual Studio [https://visualstudio.microsoft.com/vs/ here].
Professional Visual Studio versions are working fine too.


When installing Visual Studio 2017 or later, make sure to select the "Desktop Development with C++" workload.


The following libraries are needed:
Building ScummVM with Visual Studio versions older than 2015 is not supported anymore.


* [http://www.libsdl.org/download-1.2.php SDL 1.2].  
=== Needed Libraries ===
You need the file SDL-devel-1.2.9-VC6.zip (1.2.9 is the latest version at this time)
ScummVM relies on third-party libraries for common features, such as MP3 decoding. Some of these libraries, like SDL, are required, whereas others like libtheora are optional.


* [http://www.kernel.org/pub/software/devel/nasm/binaries/win32/ NASM]
We supply a set of prebuilt libraries for Visual Studio 2015 and later, which can be found [https://downloads.scummvm.org/frs/build/scummvm_libs_2015.zip here].


* [http://downloads.xiph.org/releases/ogg/ libogg] and [http://downloads.xiph.org/releases/vorbis/ libvorbis] for OGG support
These libraries have been built on Windows 8.1 using the Visual Studio 2015 Community Edition.


Note that the libraries included in the "vorbis" package won't work. You need libogg and libvorbis, not vorbis
When compiling for Windows on ARM, you will need the download the [https://devblogs.microsoft.com/directx/announcing-the-opencl-and-opengl-compatibility-pack-for-windows-10-on-arm/ OpenGL Compatibility Pack]. An updated version of the compatibility pack can be found in the Microsoft Store [https://apps.microsoft.com/detail/9nqpsl29bfff?ocid=pdpshare&hl=en-us&gl=US here].


* [ftp://ftp.mars.org/pub/mpeg/ libmad] for MP3 support
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]].


* [http://libmpeg2.sourceforge.net/downloads.html libmpeg2] for MPEG-2 support
=== Installing Libraries ===
The easiest way to make Visual Studio find the supplied libraries is by using the environment variable <code>SCUMMVM_LIBS</code>. You can set it by performing the following steps:
* Unzip the library zip to a directory of your choice, for example <code>C:\Users\YourUsername\Documents\scummvm_libs_2015</code>.
* Go to Start Menu > Control Panel > System > Advanced Settings > Environment Variables (or <code>Win</code>+<code>R</code> and then <code>SystemPropertiesAdvanced.exe</code>) and add a new variable <code>SCUMMVM_LIBS</code> 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 <code>bin\</code>, <code>include\</code>, and <code>lib\</code> directories.


Get the latest mpeg2dec release from this page, libmpeg2 is included there
== Preparing the Project Files ==


* [http://www.zlib.net/ zlib]. You need the latest zlib compiled DLL
=== Building create_project ===


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].  
ScummVM uses a configure/Make based build system. We have a tool to generate Visual Studio project files from this build system. The first step you need to take is building this tool called <code>create_project.exe</code>.


First, open the solution file <code>devtools\create_project\msvc\create_project.sln</code> (either from the File Explorer or from the File > Open project/solution menu). Then simply build the solution, with Build > Build solution. If this doesn't work, make sure that the Visual Studio C++ tools have been properly set up, as [[#Visual_Studio|explained above]].


== Building the libraries ==
The project file should automatically assure that the resulting <code>create_project.exe</code> is copied to <code>dists\msvc\</code>.


Now, we need to compile the required libraries.
=== Generating the Project Files ===


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
Simply run the batch script <code>dists/msvc/create_msvc.bat</code>. 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 <code>module.mk</code> file to assure ScummVM still builds fine with the configure/Make based build system.


=== A note about VS2005 ===
==== In case of missing dependency ====
When using the prebuilt libraries, you might be missing a dependency, and compiling could give an error complaining about a missing header, e.g. <code>fluidsynth.h</code>. You can work around this by calling <code>create_project.exe</code> directly, and passing additional arguments to enable/disable features. For example, to use FluidLite (which is included in the prebuilt libraries) instead of FluidSynth, you can create a project for all engines and FluidLite like this:<syntaxhighlight lang="powershell">
cd dists\msvc
.\create_project ..\.. --msvc --enable-fluidlite
</syntaxhighlight>


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.
== Compiling ScummVM ==


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


http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/
Simply open the generated solution file in <code>dists\msvc\scummvm.sln</code>. 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.


http://www.gamedev.net/community/forums/topic.asp?topic_id=361433
'''IMPORTANT''': If you get errors about missing DLLs, you'll need to copy them to a location Windows picks up to run the resulting binary. The easiest way to do this is to place the DLL files in the directory where <code>scummvm.exe</code> is. There are multiple folders to choose from, depending on your build configuration. For example, if you build a Win32 Debug configuration, you will need to copy them from <code>SCUMMVM_LIBS\lib\x86\Debug\</code> to <code>dists\msvc\Debugx86\</code>.


http://blogs.msdn.com/oldnewthing/archive/2005/01/07/348437.aspx
NOTE: Several people have had errors about structure packing under Visual Studio 2019. In such cases, you need to update [https://github.com/libsdl-org/SDL/releases SDL2] with the latest version.


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:
== Compiling with Console/Text Output ==


  #if (_MSC_VER >= 1400) /* VC8+ (VS2005) */
By default ScummVM is compiled as a Windows subsystem application with no console output. If you need the console, you can do one of the following:
  #pragma warning(disable : 4996) /* Disable all deprecation warnings */
* In the <code>create_project</code> command, add <code>--enable-text-console</code>.
  #endif /* VC8+ (VS2005) */
* In the Project Options for the ScummVM project, go to the Linker | System | SubSystem line, and change the <code>/SUBSYSTEM:WINDOWS</code> option to <code>/SUBSYSTEM:CONSOLE</code>
 
 
=== 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/zlib ===
 
SDL and zlib are already compiled, so we can skip the compilation step for those two
 
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, open the solution there and compile it using the LIB release configuration. Then, go to Project->Properties, Linker->Input and change the "zldll.lib" directive to "zlib.lib"
 
 
For ScummVM 0.8.0 or earlier, 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. You'll need to add the resulting library zlibwapi.lib into ScummVM. To do this, go to Project->Properties, Configuration Properties->C/C++->Preprocessor and add "ZLIB_WINAPI" in the Preprocessor Definitions field. Also, go to Linker->Input and add "zlibwapi.lib" in the Additional Dependencies field. These two are included by default up to the stable 0.8.0 release, but not in the latest CVS
 
 
=== 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, go to the configuration manager and exclude "in_flac" from compilation. This is due to the fact that you don't need that library (it's for Winamp) but also it won't compile with VS2005, because of many things that VS2005 doesn't like in tagz.cpp from Winamp's SDK. You'll also need to copy ogg_static.lib from the ogg library into the obj\release\lib folder
 
 
=== Adding all libraries to Visual Studio ===
 
Now that we got all libraries compiled, we go to Tools->Options->Projects and solutions->VC++ directories.  
 
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)
 
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
 
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
 
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.lib" in the Additional Dependencies field.
 
 
=== Before compiling ===
 
Open the solution file in dists\vc8 (or vc7 if you're using VS2003)
 
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. You need to do the same with file kyra\script_v1.cpp, although that wasn't enough for my case. I had to remove all japanese text from script_v1.cpp in order to compile it with VS. The reason for this step is that those files contain Japanese characters, so VS refuses to compile the project if those files are not saved as unicode
 
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
 
 
=== Ready to go! ===
 
OK this should be all of it (thankfully), so you should be good to go. I haven't included instructions to include FLAC, since that's not needed to build ScummVM.
 
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

Latest revision as of 09:44, 17 November 2024

Installing the needed software and libraries

In this page, we guide you through the steps to compile ScummVM with Visual Studio.

Visual Studio

You can get the free Community version of Visual Studio here. Professional Visual Studio versions are working fine too.

When installing Visual Studio 2017 or later, make sure to select the "Desktop Development with C++" workload.

Building ScummVM with Visual Studio versions older than 2015 is not supported anymore.

Needed Libraries

ScummVM relies on third-party libraries for common features, such as MP3 decoding. Some of these libraries, like SDL, are required, whereas others like libtheora are optional.

We supply a set of prebuilt libraries for Visual Studio 2015 and later, which can be found here.

These libraries have been built on Windows 8.1 using the Visual Studio 2015 Community Edition.

When compiling for Windows on ARM, you will need the download the OpenGL Compatibility Pack. An updated version of the compatibility pack can be found in the Microsoft Store here.

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

Installing Libraries

The easiest way to make Visual Studio find the supplied libraries is by using the environment variable SCUMMVM_LIBS. You can set it by performing the following steps:

  • Unzip the library zip to a directory of your choice, for example C:\Users\YourUsername\Documents\scummvm_libs_2015.
  • Go to Start Menu > Control Panel > System > Advanced Settings > Environment Variables (or Win+R and then SystemPropertiesAdvanced.exe) and add 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.

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 step you need to take is building this tool called create_project.exe.

First, open the solution file devtools\create_project\msvc\create_project.sln (either from the File Explorer or from the File > Open project/solution menu). Then simply build the solution, with Build > Build solution. If this doesn't work, make sure that the Visual Studio C++ tools have been properly set up, as explained above.

The project file should automatically assure that the resulting create_project.exe is copied to dists\msvc\.

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.

In case of missing dependency

When using the prebuilt libraries, you might be missing a dependency, and compiling could give an error complaining about a missing header, e.g. fluidsynth.h. You can work around this by calling create_project.exe directly, and passing additional arguments to enable/disable features. For example, to use FluidLite (which is included in the prebuilt libraries) instead of FluidSynth, you can create a project for all engines and FluidLite like this:

cd dists\msvc
.\create_project ..\.. --msvc --enable-fluidlite

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: If you get errors about missing DLLs, you'll need to copy them to a location Windows picks up to run the resulting binary. The easiest way to do this is to place the DLL files in the directory where scummvm.exe is. There are multiple folders to choose from, depending on your build configuration. For example, if you build a Win32 Debug configuration, you will need to copy them from SCUMMVM_LIBS\lib\x86\Debug\ to dists\msvc\Debugx86\.

NOTE: Several people have had errors about structure packing under Visual Studio 2019. In such cases, you need to update SDL2 with the latest version.

Compiling with Console/Text Output

By default ScummVM is compiled as a Windows subsystem application with no console output. If you need the console, you can do one of the following:

  • In the create_project command, add --enable-text-console.
  • In the Project Options for the ScummVM project, go to the Linker | System | SubSystem line, and change the /SUBSYSTEM:WINDOWS option to /SUBSYSTEM:CONSOLE