Logo Glusoft
Become a Patron! Buy me a coffee!

Installation with Visual Studio

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.

Visual Studio 2017

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 :
SDL2 compiled for windows

The next thing to do is create an empty C++ project with Visual Studio: File > New > Project...

Create C++ project with visual studio

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

Add SDL2 include path part 1

Click on the down arrow on Additionnal include directories

You should have a new window with :

Add SDL2 in the include path part2

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

Add SDL2 lib path part1

Then add the path to the lib folder.

Add SDL2 lib path part2

We need to tell visual studio witch lib files to use, for that you will need to go in Linker > Input > Additionnal Dependencies

Add SDL2 lib entry part1

The two entries to add are:

Add SDL2 lib entry part2

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

remove precompiled headers

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;


	return 0;

We can build the program and everything should compile just fine.

Build SDL2

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!

Launch Initialization SDL2

If there is a problem, the program will exit with the return code 1

Post Comments
Dark theme