PCSX2 Documentation/Compiling on Windows

From PCSX2 Wiki
Revision as of 22:10, 10 June 2020 by Lightningterror (talk | contribs) (Remove dx sdk info, no longer needed.)
Jump to navigation Jump to search

Setting up the Build Environment

In order to compile PCSX2 you will need to configure a working build environment based on Microsoft's Visual Studio. There are some things to download, so I've placed links to them at the front of the guide so you can get everything you'll need at the first step.

Downloading the Prerequisites

Downloading build environment

First you have to download a build environment. Microsoft Visual Studio 2019 and 2017 are capable of compiling PCSX2. At this time, the recommended build environment is Visual Studio 2019 Community.

Downloading additional prerequisites

A Visual C++ redistributable runtime matching the build environment major release (Only needed if you're compiling the Installer):

Installing Microsoft Visual Studio

Microsoft Visual Studio 2019 and 2017 are capable of compiling PCSX2. Depending on whether or not you develop professionally, as well as other factors, you may or may not have access to a copy of Microsoft Visual Studio Professional. This guide will cover the installation and configuration of Visual Studio 2019 Community Windows Desktop.

Installing Visual Studio Community 2019

Download Visual Studio Community 2019 installer from the link above, and run it.

  1. Run the installer.
  2. Within Workloads tab make sure Desktop development with C++ is checked.
  3. I recommend keeping the default installation location. Click Install.
  4. The components will be downloaded and installed on your computer.
  5. Once the installation has finished, you may be prompted to restart the system.
  6. Click Restart Now or Close depending on your situation.

Configuring the Build Environment

Because the only remaining dependency required by PCSX2 is DirectX SDK and because it can be located via an environment variable, all the necessary path related tweaks were integrated into the codebase, so there is no more configuration of build environment to perform.

Getting the Source Code

If using a command-line git client like Git Bash you have to do the followings:

  • navigate to a folder that will host the repository;
  • clone pcsx2 repository.

Example: <source lang="powershell"> cd /dev/projects git clone --recurse-submodules https://github.com/PCSX2/pcsx2.git pcsx2 </source>

  • enter repository

<source lang="powershell"> cd pcsx2 </source>

  • create a dev branch and switch to it (optional). Good git practices recommend to never develop in master branch.

<source lang="powershell"> git branch dev git checkout dev. </source> I named my working branch dev, but it can have any name. When ready proceed to next step.

Compiling PCSX2's Binary

You've now completed all of the "leg work" required in order to compile PCSX2 on your machine. Congratulations!

Compiling Git Builds of PCSX2

Open the PCSX2 directory you have downloaded the source code into (in this case, C:\Development\Project Source\PCSX2) and double-click on the solution file (PCSX2_suite.sln). This will open Visual Studio (if it is not already open) and you will see a screen similar to this.

Build Target Selection

At the top of your screen, you will see a small drop down list which contains what is known as your "Build Target", as shown in the screenshot. This menu corresponds to the build of PCSX2 that you will be compiling. SSE2, SSSE3, SSE4, AVX, AVX2 refer to CPU instruction sets and only apply to the GSdx Plugin (though they compile the full solution as well). The Release Build Target does not specify an instruction set target for the GSdx compile and will not compile GSdx. It is recommended that you choose all five (SSE2, SSSE3, SSE4, AVX and AVX2) as a build target (Release is unnecessary) if preparing a release build to ensure that all users have available versions of the plugin. Once you have selected the Build Target, it is time to build the solution. You can either select the Build Menu from the top menu, and choose Build Solution, or use the appropriate shortcut key. This is the moment of truth! If you've followed the instructions properly, this process should finish with 0 errors. Warnings are usually nothing to worry about, so, as long as the solution compiles with 0 errors and you have the output files, you should be good to go. Congratulations!

Effective Build Troubleshooting Steps

So, your build failed. What now? Even in the most perfect of circumstances, there is always the possibility that your build is going to fail for some reason or another. I've included a few things to try that should take care of almost all of the common compiling issues that users have.

If at first you don't succeed, retry the build, at least once. Visual Studio is notorious for spamming errors about files being in use, access denied, or errors returned from mt.exe. If this happens to you, or frankly in pretty much any other case, make sure to retry the build at least once to ensure you have a reproducible build failure!

It is good practice to clean your build environment of Visual Studio build-process temporary files and post-build remnants of the solution if you encounter errors while building. This is a quick and painless process. To begin, open the PCSX2_suite.sln Solution file. Once Visual Studio has opened, select the build of PCSX2 that you are having trouble building from the Build Target dropdown (e.g., SSE2, SSSE3, SSE4, etc.) Click on the Build menu and select Clean Solution from the list. Try to build again, and see if this solves your problem.

When all else fails, the error log and output screens can be a wealth of information. Even if you're not a developer, you can look at the error log and extrapolate what files are involved in the error you're having. Once you know that, search for the files and see if any of them are in the directories that are supposed to be configured in the search paths -- if so, go verify in your VC++ Directories setting that you have properly entered the dependency directories. Mistyping the directory names, including the wrong directory, or overlooking a directory is one of the most common causes of build failure and can be easily and quickly fixed. If that doesn't work, post about your experiences on the PCSX2 forum under the relevant topic and someone should be able to help you out.

Stopping Unwanted Components from Compiling

If you are developing a specific project and do not want to compile the other projects every time you re-build the solution, or if you just don't want to compile a specific plug-in for some reason or another, you can easily accomplish this. Open the PCSX2_suite.sln Solution file and right-click on the Project you wish not to compile. Select "Unload" from the context menu. You will now see that the project is listed as "(Unavailable)", as shown in the screenshot. When you compile, this solution will be skipped. Best of all, this option is persistent, but does not write to the Solution (.sln) file, so this change will not be included in your your Git commits.

Running PCSX2 from the Visual Studio Debugger

It is possible (and quite easy) to run PCSX2 from the Visual Studio Debugger, if you feel so compelled to do so. See below for instructions on how to do it for all supported version of Visual Studio.

Select build target from top, just like you would do to build PCSX2, then press F5. If you are an experienced developer you can even mess with Configuration manager to debug specific components of PCSX2, certain plugins for example.

Packaging PCSX2 with Nullsoft Scriptable Install System

Just Because It Compiles Doesn't Mean It Works!

The steps included in this guide will pretty much guarantee that you can set up an environment in which you can compile the .NSI file included in the PCSX2 source to a .exe installer, but PLEASE NOTE THE FOLLOWING: Just because you can get it to compile without erroring does not mean that the output file will be a functional installer! Just like any other piece of code, the .NSI installer needs maintenance whenever there are changes to the file and directory structure of PCSX2. The installer is not the highest priority on the list, so it is possible that the .NSI is out of date and may be including out-dated files, or may not be including new files. It may complete compilation but net an installation that crashes every time it's run due to missing or unlinked .DLLs. With that said, it is NOT recommended that you use these installers without testing them in a sandbox / virtualized environment first to ensure that they properly install! A successful .NSI file compile does NOT equate to a truly successful installer build!

Installing the Nullsoft Scriptable Install System

Download the installation package from the link above and run it. You will be presented with this Welcome Screen. Click Next. Accept the terms of the EULA. Select "Full Install", if it is not already checked. It is recommended that you keep the default installation directory, and click Next. The Nullsoft Scriptable Install System will install very quickly and present you with the final screenshot. Click Finish and the installer will close.

Lastly, you need to copy the vc_redistx86.exe that you downloaded from the prerequisites above into the following directory:

C:\Development\Project Source\PCSX2\NSIS\

If you skip this step, the NSIS compile will fail. This file must be present for any branch of PCSX2 as well, including wxGUI.

Packaging PCSX2 with NULL Plugins

After you install NSIS and .NSI files are associated with the Nullsoft Scriptable Installer System, you can Right-Click on .NSI files and select "Compile NSIS Script", as shown in the picture.


This will compile a PCSX2 installer and include all of the null plugins. This will NOT include the additional plugins (gsDX, SPU-X, etc.)

Packaging PCSX2 with all Plugins

In order to compile PCSX2 and include the Plugins, you must specify the INC_PLUGINS variable to makensis.exe. To do this, run the following in a command prompt (assuming default installation directories):

<source lang="powershell">"C:\Program Files\NSIS\makensis.exe" "C:\Development\Project Source\PCSX2\NSIS\pcsx2_installer_script.nsi" /DINC_PLUGINS</source>

This will compile PCSX2 and include all of the plugins in the installer file.