Like any other C++ libraries you download the latest version.
If you want to compile SDL2 you need to pick the source code.
If you want to have your program ready without complexities, SDL2 is avaible compiled in the Development Libraries category.
Here I will assume you have taken the precompiled package for windows.
I have downloaded the package SDL2-devel-2.0.9-VC.zip after that I need to extract the package in the folder where I put all my libraries.
You will obtain a folder containing the following files and folders :
The next thing to do is create an empty C++ project with Visual Studio:
File > New > Project...
Confirm the creation with OK
Right click on the project > Properties
Check at the to left the configuration is on Release, and then go to C/C++ > General
Click on the down arrow on Additionnal include directories
You should have a new window with :
Add the path to the include folder.
When everything is done you need to Apply the changes and confirm with OK
The next thing to do is to return to the properties then go to Linker > General > Additionnal Library Directories
Then add the path to the lib folder.
We need to tell visual studio witch lib files to use, for that you will need to go in Linker > Input > Additionnal Dependencies
The two entries to add are:
When everything is done you need to Apply the changes and confirm with OK
In the project you need delete the precompiled header phc.h and phc.c and then return in the properties :
C/C++ > Precompiled Headers > Not Using Precompiled Header
Replace the main of the program with:
#include <iostream>
#include "SDL.h"
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
std::cout << "Unable to initialize SDL: " << SDL_GetError();
return 1;
}
SDL_Quit();
return 0;
}
We can build the program and everything should compile just fine.
After the project is built the last thing to do is to add the file SDL2.dll into the Release folder of the solution, the one containing the executable.
Basically the program do nothing, just initilise and close SDL, so how do we know the installation is succeful.
If you see in the visual studio console : has exited with code 0 (0x0) everything is working!
If there is a problem, the program will exit with the return code 1