PCSX2 Documentation/Compiling on Windows: Difference between revisions

From PCSX2 Wiki
Jump to navigation Jump to search
Line 100: Line 100:


===Installing SDKs===
===Installing SDKs===
Recent revisions of PCSX2 only require DirectX SDK to compile successfully. OpenGL Extension Wrangler library becoming redistributable allowed its integration into the codebase. nVidia CG Toolkit, now defunct, its functionality has been replaced by other libraries which are now part of build environmemt.
Recent revisions of PCSX2 only require DirectX SDK to compile successfully. OpenGL Extension Wrangler library becoming redistributable allowed its integration into the codebase. nVidia CG Toolkit, now defunct, its functionality has been replaced by a more popular shading language called GLSL. This shading language is now implemented in all graphics driver releases.
====DirectX SDK====
====DirectX SDK====
DirectX SDK installer is a problematic peace of software as installers that drop unsolicited software on target machine behind user's back are nothing good mainly due to 2 reasons:
DirectX SDK installer is a problematic peace of software as installers that drop unsolicited software on target machine behind user's back are nothing good mainly due to 2 reasons:

Revision as of 20:11, 18 January 2015

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. At this moment the recommended build environment is Visual Studio 2013 Express for Windows Desktop.

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


This section is severely obsolete. Bringing it up to date requires extended research in order to rebuild it from scratch


At present, there are three versions of Microsoft Visual Studio that 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 2008 Standard. To ensure the widest applicable audience, this guide will cover the installation and configuration of all three of these versions. Note, however, that it is only required for you to install one of them!

Installing Microsoft Visual Studio 2008 Standard Edition

  1. Insert your Visual Studio 2008 Standard CD (or download the Trial from the link above). Run setup and click next at the Welcome Screen (shown below). It's your choice as to sending information about the setup experience to Microsoft.
  2. Accept the terms of the EULA and enter your product key.
  3. The Visual Web Developer and Visual Basic features are not required in order to compile PCSX2, however, if you program in any of these languages, you may elect to install them and it will not cause any problems. Make sure to install Visual C++. I recommend keeping the default installation paths.
  4. Visual Studio will begin installing.
  5. Once setup is complete, you will be presented with the following screen. Click Finish.
  6. Now that Visual Studio is installed, your system needs a few patches in order to be current. Visiting Windows Update with Microsoft Update enabled shows the following:
  7. Install all of the updates and then Visual Studio 2008 is ready to go. Skip the Visual C++ 2008 Express and Visual Studio 2010 Professional sections and continue below with Installing SDKs.

Installing Microsoft Visual Studio 2008 Express Edition

Download the Visual C++ 2008 Express Edition Installer from the link above. Run it, and click next at the Welcome Screen (shown below).

  1. Accept the EULA. It's your choice whether or not you allow it to display online and RSS content, it doesn't make a difference to the compiling of PCSX2.
  2. You do not need Microsoft SQL Server 2008 Express Edition in order to compile PCSX2, however, if you are doing development in any other capacity that requires a local SQL Database, you may choose to install this component.

I# recommend keeping the default installation location. Click Next.

  1. The components will be downloaded to your computer.
  2. Once done downloading, they will then be installed.
  3. Once the installation has finished, you will see the following screen.
  4. Click Finish and the installer will close. Now that Visual C++ is installed, your system needs a few patches in order to remain current. Visiting Windows Update with Microsoft Update enabled shows the following:
  5. Download and install the updates, and then skip past Installing Visual Studio 2010 Professional and continue with the SDK installations.


Installing Microsoft Visual Studio 2010 Professional (Beta 1)

NOTE: Visual Studio 2010 is not presently a supported build environment for PCSX2. The instructions and configuration information below are provided sheerly for completeness's sake as Visual Studio 2010 will ultimately be a supported build platform, and this information will be updated as it nears completion and release. It is not recommended that you attempt to build PCSX2 with Visual Studio 2010 at this time.

  1. Download the Visual Studio 2010 Professional Web Installer from the link above. Run it, and click next at the Welcome Screen (shown below). Yes, it will have the Visual Studio Team System logo even though you downloaded Visual Studio 2010 Professional and the titlebar and actual text say so. Don't ask me. Ask Microsoft.
  2. Accept the EULA and enter your Product Key, then hit Next.
  3. The .NET Development Environment is NOT required in order to configure PCSX2, but you can choose to install it if you plan on doing .NET Development. I recommend installing Visual Studio in the default location to ensure there are no problems later on.
  4. Visual Studio's installer will begin downloading the installation components.
  5. Once it has finished downloading the components, it will begin installing them.
  6. Soon after beginning the installation, I was prompted to reboot in order to continue.
  7. After I rebooted and logged on, I got the following at system startup:
  8. The installer then launched and continued installing where it had left off.
  9. After that finishes, you should be presented with the following screen:
  10. Click finish and the installer will close. Now that Visual Studio is installed, your machine needs several more patches in order to be current. Visit Windows Update with Microsoft Update enabled and you'll be presented with the following updates
  11. The SQL Server update isn't required for PCSX2, but is recommended in general to keep your machine as up-to-date as possible. After the updates have installed, Visual Studio 2010 Professional is now installed on your computer. Go ahead on to the next step.

Installing SDKs

Recent revisions of PCSX2 only require DirectX SDK to compile successfully. OpenGL Extension Wrangler library becoming redistributable allowed its integration into the codebase. nVidia CG Toolkit, now defunct, its functionality has been replaced by a more popular shading language called GLSL. This shading language is now implemented in all graphics driver releases.

DirectX SDK

DirectX SDK installer is a problematic peace of software as installers that drop unsolicited software on target machine behind user's back are nothing good mainly due to 2 reasons:

  1. the unsolicited software eats system resources, this is even more unpleasant if any of these unsolicited peaces of software is never used;
  2. in these days when IT security threats are at large any unsolicited software is equivalent to a collection of security holes.

Experimented with this installer on a virtual machine and discovered it installs the following components without consent:

  • .NET Framework v2.0
  • Visual C++ 2008 Redistributable runtimes
  • Visual C++ 2010 Redistributable runtimes

None of these software products are any more supported by Microsoft, meaning no more security patches and none of these are needed to build PCSX2. Bellow are described 2 ways of installing DirectX SDK, one secure and minimal and another easier but dirty and insecure.

Secure and minimal installation
  1. Download the DirectX SDK Web Installer and 7-zip;
  2. Install 7-zip with default settings, the installer in executable format it's by far the easiest to use and has minimum system footprint;
  3. Open 7-zip and navigate to folder where you downloaded DirectX SDK installer;
  4. Right click on the installer and Select 7-Zip - Open Inside, this opens the installer as an archive;
  5. Extract Lib and Include to a folder that will host DirectX SDK. If that folder doesn't exist it's going to be created;
  6. Set DirectX SDK environment variable (DXSDK_DIR).
Setting DirectX SDK environment variable

There is a large palette of possibilities of setting DirectX SDK environment variable (DXSDK_DIR):

  • as system environment variable;
  • as an environment variable for currently logged on user;
  • programmatically.

There are some important conditions regarding the value of this environment variable:

  • it must be an absolute folder path or an expression that evaluates to an absolute folder path;
  • it must end with an extra "\".

Examples: <source lang="powershell"> c:\dev\dep\dxsdk ..\dep\dxsdk </source> are both incorrect because they don't end with "\" and even more, the second one is not an absolute path. <source lang="powershell"> c:\dev\dep\dxsdk\ </source> is correct.

Now that we know what kind of value DXSDK_DIR must have, all that's left is to set it. There are various guides online describing how to set an environment variable using various editions of Windows, so I will not enter in details, instead I'll describe a tip on how to easily set DXSDK_DIR programmatically using Git Bash. This git client has 2 launchers: one with UNIX-like interface and another using Windows command prompt itself, both launchers being batch scripts. The one that interests us is the simpler batch file, that one that opens Windows Command Prompt.

Most of this batch script looks like this: <source lang="powershell"> @rem Do not use "echo off" to not affect any child calls. @setlocal

@rem Get the absolute path to the current directory, which is assumed to be the @rem Git installation root. @for /F "delims=" %%I in ("%~dp0") do @set git_install_root=%%~fI @set PATH=%git_install_root%bin;%git_install_root%mingw\bin;%git_install_root%cmd;%PATH%

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH% @if not exist "%HOME%" @set HOME=%USERPROFILE%

@set PLINK_PROTOCOL=ssh @if not defined TERM set TERM=msys </source> If both PCSX2 repository and git installation folder are under a common folder, and if we create a batch file with this source in that common folder, we can set DXSDK_DIR using git_install_root value. For example we have a folder tree that looks like this: <source lang="powershell"> c:\dev\dep \

               dxsdk\
      git     \  
      projects\      
               pcsx2\

</source>

  • The batch file goes in c:\dev
  • git_install_root variable value in this case is c:\dev\

We need to do some tweaks to our batch script in order to work:

  • Thirst we have to adjust the line that customizes PATH. In this case just add git\ after %git_install_root% on all 3 spots;
  • Append a code line where DXSDK_DIR is set:

<source lang="powershell"> @set DXSDK_DIR=%git_install_root%dep\dxsdk\ </source>

  1. Append a command that launches Visual Studio.

Finding the location of Visual Studio executable is easy. Just right click on Visual Studio Start Menu entry or Start screen tile (on Windows 8/8.1) and click properties. Grab the contents of the target field and past it in the batch file source. You can insert an @ prior to that code to inhibit display output. When ready proced to next step.

Standard (dirty and insecure installation)
  1. Download the Web Installer from the link above. Run it, and click next at the Welcome Screen (shown below.)
  2. Accept the EULA as shown.
  3. You will be prompted to join the Windows Customer Experience Improvement Program. I chose not to, but the decision is yours to make. It won't impact anything you'll be doing with the software.
  4. You will then be prompted for a destination folder, I recommend choosing the default to make life easier later on.
  5. You will be prompted with a list of components.Only headers and libs are needed to build PCSCX2, the rest are entirely subject to your choice if you need them. Then go ahead and click Next.
  6. The DirectX SDK will then begin installing.
  7. You should then be presented with this screen.
  8. Click finish and move on to the next step.

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 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 matching your build environment major release (pcsx2_suite_2010.sln, pcsx2_suite_2012.sln or pcsx2_suite_2013.sln). This will open the appropriate build environment (if it is not already open) and you will see a screen similar to this.

On more recent versions of Visual Studio the solution explorer panel is on the right side instead of left.

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

This section is severely obsolete. Bringing it up to date requires extended research in order to rebuild it from scratch


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... Re-try 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! CL.EXE Compiling Errors w/ Visual Studio 2008 Standard If you are using Visual Studio 2008 Standard and have followed this guide from start to finish and are experiencing build errors in relation to CL.EXE, a workaround is to put the VS2008 install disc in and to modify your installation of VS and add Visual C#. Note that you're not installing C# because any of PCSX2 is programmed in C#, you're installing C# because for some reason, the C++ install doesn't put the necessary version of CL.EXE in your build environment. I'm investigating why this is and will update the guide if I find a better way to solve the missing CL.EXE problem. I had this problem in two specific cases but I've been shown instances where it was unnecessary. As such, I pulled it from the main steps and added it as a possible workaround in case anyone else encounters it. It seems to only occur when running under a Virtual PC in Virtual PC 2007. Clean your Dev Environment 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_2008.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. Once this has completed, run clean_msvc.cmd in the main PCSX2 SVN directory. This will clean out more unneeded data that Visual Studio leaves behind in a clean. Retry the build and see if this solves your problem. Re-download the Source It is possible (though very uncommon) for such drastic changes to be made to the source tree in SVN that you may have stale code or remnants of previous SVN revisions that have ended up sitting in your SVN directory. A quick and non-destructive way to test this is to create a new build directory and re-checkout the source from the SVN repository. After a full fresh checkout, attempt the build again. Read the Logs - Trace the Errors 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 revelant topic and someone should be able to help you out.

Files Necessary from Build for PCSX2's Execution

PCSX2 only requires a few files in order to execute. Other files are required in order for it to function as an emulator, such as the plug-in files, but in this section I am referring only to which files are required in order for PCSX2 to execute successfully without errors.

Git Build Files. The current Git build requires the following files in order to execute:

pcsx2.exe
w32pthreads.v3.dll
gnu_gettext.dll

If you will be using a debug build of GSdx, the following additional file is necessary and must be put into your pcsx2\bin directory:

glew32.dll

Miscellaneous PCSX2 Compiling Options

As with any project, the PCSX2 project has several configurable options in relation to compiling.

PCSX2 Target Build Directory One of the options is a configurable post-build event that can optionally copy the .EXE file and required .DLL files into a folder of your choice. The files are copied both as their original filename (e.g., PCSX2.EXE) and also as a revision-tagged filename for easy regression testing (e.g. PCSX2-r1750.EXE) You will need to specify the PCSX2_TARGET_COPY Environment Variable. To do this, open the Run dialog (Hit the Windows key and R at the same time) and type "sysdm.cpl" (without quotes) and hit enter. You will be presented with a screen similar to the screenshot. Switch to the Advanced Tab and you will see the something similar to the screenshot. Click on the Environment Variables button at the bottom and you will see something similar to the screenshot. Click on New under the User Variables section and enter the information as shown in the screenshot. Once you have done that and click OK, you should see something like the screenshot. Now, when you compile PCSX2, a build copy will be placed in the directory you specified! (Make sure it exists!) You will need to log off and log back in for this to take effect!

1	 2	 3	 4	 5

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_2008.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 making this change will not cause you to get warned of a Version Conflict every time you update your SVN in the future.

1	 2

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.

1	 2	 3	 4	 5

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

1

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):

"C:\Program Files\NSIS\makensis.exe" "C:\Development\Project Source\PCSX2\NSIS\pcsx2_installer_script.nsi" /DINC_PLUGINS

This will compile PCSX2 and include all of the plugins in the installer file. Packaging the PCSX2 wxGUI Branch Due to a few changes in the versioning (and some not yet up-to-date code), you will need to make some changes to the pcsx2_installer_script.nsi in order to get a working installer for the wxGUI trunk. Update to the latest SVN revision and check the .NSI file at (or around) line 103. You may see the following:

   SetOutPath $INSTDIR
   File /oname=pcsx2-r${SVNREV}.exe
   ..\bin\pcsx2.exe
   File ..\bin\w32pthreads.dll
   File ..\bin\gnu_gettext.dll

Note that it is referencing w32pthreads.dll even though the wxGUI branch of PCSX2 uses an updated w32pthreads.v2.dll. Change the code to read

   SetOutPath $INSTDIR
   File /oname=pcsx2-r${SVNREV}.exe
   ..\bin\pcsx2.exe
   File ..\bin\w32pthreads.v2.dll
   File ..\bin\gnu_gettext.dll

and close the file. Note that updating the SVN after you make this change may alert you that your copy and the copy on the server do not match. This means that the NSI file has changed in the repository and you should re-download it. If you update and get an error from NSIS about being unable to find w32pthreads.dll, you'll know what to do to fix it. Once that is done, follow the same process as is outlined above for the PCSX2 Trunk SVN.