Difference between revisions of "Compiling ScummVM/Visual Studio"

From ScummVM :: Wiki
Jump to navigation Jump to search
(Updated the zlib compilation instructions again)
(Add link to MS OpenGL compatibility pack)
 
(63 intermediate revisions by 14 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.


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


=== Visual Studio 2008 ===
=== Needed Libraries ===
There exist several versions of Visual Studio 2008. A feature comparison can be found
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://msdn.microsoft.com/vstudio/products/compare/default.aspx here]


You can obtain the free Express version of VS2008 [http://msdn.microsoft.com/vstudio/express/default.aspx here]
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].


Although Visual Studio 2008 is preferred if you happen to use the older Visual Studio 2005
These libraries have been built on Windows 8.1 using the Visual Studio 2015 Community Edition.
you have to have at least Service Pack 1 installed for it (as Visual Studio 2005
without Service Pack 1 has problems with ScummVM's template code).


=== Precompiled libraries ===
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].
To ease the whole process, a package of all the needed precompiled libraries has been created.
All you need to do is:
* Download the precompiled libraries and the [http://www.libsdl.org/release/SDL-1.2.12-win32.zip latest SDL runtime library] - latest version is 1.2.12 at the time this was written, you can find the latest version [http://www.libsdl.org/download-1.2.php here]. Mirrors for precompiled libraries:
** [http://robertmegone.com/scummvm/build/scummvm_vs_libs.zip Mirror 1]
** [http://rapidshare.com/files/178729751/scummvm_vs_libs.zip Mirror 2] (RapidShare)
* Unzip the precompiled libraries archive maintaining directory structure
* Run install.bat (Visual Studio 2005/2008 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 and 2008. 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/Visual_Studio#Adding_all_libraries_to_Visual_Studio|Adding all libraries to Visual Studio]]" further on
* Unzip sdl.dll from the SDL runtime in the same directory where the scummvm executable will be created (default is under dits\msvc9\scummvm_Release, substitute msvc9 for msvc8 if you're using Visual Studio 2005 and msvc7 if you're using Visual Studio 2003)
* Skip to step "[[Compiling_ScummVM/Visual_Studio#Ready to compile ScummVM|Ready to compile ScummVM]]"


=== Libraries needed ===
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://www.libsdl.org/download-1.2.php SDL 1.2], file SDL-devel-1.2.XX-VC8.zip (where XX is the current release number)
=== Installing Libraries ===
Latest stable version at the time of writing this: [http://www.libsdl.org/release/SDL-devel-1.2.13-VC8.zip 1.2.13]
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.


* [ftp://ftp.zytor.com/pub/nasm/releasebuilds/ NASM]
== Preparing the Project Files ==
Latest stable version at the time of writing this: [ftp://ftp.zytor.com/pub/nasm/releasebuilds/2.06rc12/win32/nasm-2.06rc12-win32.zip 2.06rc12]


* [http://downloads.xiph.org/releases/ogg/ libogg] and [http://downloads.xiph.org/releases/vorbis/ libvorbis] for OGG support.
=== Building create_project ===
Note that the libraries included in the "vorbis" package won't work. You need libogg and libvorbis, not vorbis.
Latest stable versions at the time of writing this: [http://downloads.xiph.org/releases/ogg/libogg-1.1.3.zip 1.1.3] and [http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.0.zip 1.2.0].


* [ftp://ftp.mars.org/pub/mpeg/ libmad] for MP3 support.  
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>.
Latest stable version at the time of writing this: [ftp://ftp.mars.org/pub/mpeg/libmad-0.15.1b.tar.gz 0.15.1b]


* [http://sourceforge.net/project/showfiles.php?group_id=13478&package_id=12677 libFLAC] for FLAC support.
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]].
Latest stable version at the time of writing this: [http://sourceforge.net/project/showfiles.php?group_id=13478&package_id=12677&release_id=539981 1.2.1]


* [http://libmpeg2.sourceforge.net/downloads.html libmpeg2] for MPEG-2 support.
The project file should automatically assure that the resulting <code>create_project.exe</code> is copied to <code>dists\msvc\</code>.
Get the latest mpeg2dec release from this page, libmpeg2 is included there.
Latest stable version at the time of writing this: [http://libmpeg2.sourceforge.net/files/libmpeg2-0.5.1.tar.gz 0.5.1]


* [http://www.zlib.net/ zlib]
=== Generating the Project Files ===
You need the latest zlib source code. If you wish to compile ScummVM 0.8.0 or earlier with zlib support, you'll also need [http://www.winimage.com/zLibDll/crtdll.zip crtdll.lib].
Latest stable version at the time of writing this: [http://www.zlib.net/zlib123.zip 1.2.3]


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.


== Building the libraries ==
== Compiling ScummVM ==


Now, we need to compile the required libraries.
If you followed all the steps, you are now ready to compile ScummVM with Visual Studio. Congratulations!


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 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.


'''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>.


=== A note about VS2008/2005 ===
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're building the libraries with VS2008/2005, 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 with Console/Text Output ==


Read more here:
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 <code>create_project</code> command, add <code>--enable-text-console</code>.
http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/
* 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>
 
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 ===
 
You'll need the zlib source package. After unzipping it, go into the projects directory in the zlib source and open the solution under projects\visualc6. Right click on the "zlib" project, and go to its properties. Then, go to Configuration Properties->C/C++->Code Generation and change the Runtime library from "Multi-Threaded DLL (/MD)" to "Multi-Threaded (/MT)" (if you don't do this step, you'll have issues compiling ScummVM later on). Then, compile the "zlib" project using the LIB release configuration.
 
 
=== 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
 
 
=== libmpeg2 ===
 
The VC6 solution files (inside the vc++ folder) need to be used for this library, but first they all need to be changed to DOS format, otherwise Visual Studio will complain that the project files are corrupted. Then, open file config.h inside the vc++ folder and comment out the following line, near the end of the file:
#define restrict __restrict
Open the solution and compile project "libmpeg2". After you compile it, go to its include directory, create a folder "mpeg2dec" in there and copy all files from the include folder in this subfolder. You will 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 ===
 
Open and compile the "libmad" solution
 
 
=== FLAC ===
 
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)
<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)
<br><br>
 
=== Second method: Tell VC++ where to look ===
The '''second method''' is to tell VC++ where to look for the required libraries and header files
 
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_static.lib" in the Additional Dependencies field.
 
 
== Enabling the console ==
 
Since information on doing this is not that easy to find, here's how to enable the console in the resulting ScummVM executable.
The default project subsystem is "Windows" instead of "Console", which means that the console will not be shown.
 
To show the console, right-click on the "scummvm" project and go to Properties. There, go to Configuration Properties->Linker->System and change the "Subsystem" property from "Windows (/SUBSYSTEM:WINDOWS)" to "'''Console (/SUBSYSTEM:CONSOLE)'''". Then, go to Linker->Advanced and set the entry point to be "'''WinMainCRTStartup'''" (special thanks to [[User:Jubanka|Jubanka/knakos]] for his tip on entrypoint).
 
 
== Ready to compile ScummVM ==
 
If you got all the libraries compiled, you're ready to compile the latest version of ScummVM!
 
Open the solution file in dists\msvc9 (msvc8 for VS2005 and msvc7 for VS2003), select the "Release" configuration from the configuration manager pulldown menu and then go to Build->Build solution, or just press Control-F7 to compile it.
 
The ScummVM executable should be in the folder dists\msvc9\scummvm_Release as "scummvm.exe".
 
You'll need to copy sdl.dll from the SDL runtime archive (or the latest devel archive) in the directory where scummvm.exe is

Latest revision as of 21:39, 27 August 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.

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