How to Set Up SDL with Visual Studio

Author Info

Updated: February 24, 2020

Whether you're a novice C++ programmer or a veteran software developer, graphics programming is an educational and rewarding experience. Simple DirectMedia Layer is a C library (compatible with C++) that allows simple, low-level access, to the graphics functionality of a variety of platforms. This guide will help you get over the first challenge of using SDL: installing and setting it up. It is assumed you work with Windows and Visual Studio 2019.

After setting up SDL on a project, create an Export Template (See Method "Creating Project with SDL Template") to create SDL projects without setting up again.

Method 1 of 10:
Configuring Visual Studio

  1. 1
    Highlight step or sub-step. Highlight step or sub-step you expect to do and then do it. See as example picture above.
  2. 2
    Download Visual Studio 2019. If you have not done so you can download it from https://www.visualstudio.com/downloads.
  3. 3
    Check the Desktop development with C++ workload box as you download. If necessary scroll down the page.

Method 2 of 10:
Downloading SDL

  1. 1
    Create folder GL. In directory (disk) C:, right click > select New > Folder > type GL < hit Enter.
  2. 2
    Download the last version of SDL2. Right click on the following link and select Open Link in New Window https://www.libsdl.org/download-2.0.php. Scroll to the bottom of the page and find Development Libraries. Click the version just below "Windows:" (see the picture above). Today it is SDL2-devel-2.0.10-VC.zip (Visual C++ 32/64-bit).
    • In downloading window you have the folder SDL2-2.0.10, (or the last version). Click it > right click > select Copy. (Or, alternatively, click it and drag into C:\GL).
    • Navigate to C:\GL. Inside GL, right click > select Paste.
    • Click on name SDL2-2.0.10, (or the last version), and rename to SDL2. Now in folder GL you have folder SDL2.

Method 3 of 10:
Creating Visual Studio Project

  1. 1
    Create an empty project. .
    • If Visual Studio 2019 is not opened. Open it > Click Create a new project > Empty Project > Next.
      • In "Project name" text field type: Project-0.
      • Next to "Location" text field click ... > Navigate to C: > GL > click Select folder. Now "Location" is C:\GL\.
      • Check "Place solution and project in the same directory" > click Create. Wait till Visual Studio 2019 instance appears.
    • If Visual Studio 2019 has already been opened. Click File > New > Project… > Create a new project > Empty Project > Next. The rest as above.
  2. 2
    Add your Source file to the project.
    • In "Solution Explorer" window right click the "Source Files" folder (the last one).
    • Click "Add > "New Item…"
    • In the "Add New Item - Project-0" window, click "C++ File (.cpp)", the first one. "Name:" Source.cpp is okay.
    • The "Location" should be C:\GL\Project-0\. If it's not so, click ... to the right of the field and navigate to C: > GL > Project-0. Click "Select folder". Now "Location" is C:\GL\Project-0\.
    • Click the Add button. The file will open in the main text editor but leave the file blank for now.

Method 4 of 10:
Setting Up SDL2 in Project

  1. 1
    Configure project's Properties. In "Solution Explorer" right click on the name of your project, that is Project-0, and select "Properties". Leave default settings: Configuration: Active(Debug), and Platform: Active(Win32).
  2. 2

Method 5 of 10:
Testing your Project

  1. 1
    Test your project. Copy following code and paste in Source.cpp code area. Hit Ctrl+F5. If the project builds and a white window with title "An SDL2 window" appears, then the project was set up correctly. You are now ready to program with SDL.
#include "SDL.h"

int main(int argc, char* argv[])
{	
	SDL_Init(SDL_INIT_VIDEO);

	SDL_Window* window = SDL_CreateWindow
       ("An SDL2 window", // window's title
	10, 25, // coordinates on the screen, in pixels, of the window's upper left corner
        640, 480, // window's length and height in pixels  
	SDL_WINDOW_OPENGL);

	SDL_Delay(3000); // window lasts 3 seconds
	SDL_DestroyWindow(window);
	SDL_Quit();
	return 0;
}

Method 6 of 10:
Correcting errors if any

  1. 1
    In "Error List" if you see error
    • cannot open file SDL.h, go to Part 4, step 1, Configure project's Properties, sub-step Configure "Additional Include Directories" and follow instructions.
    • cannot open file SDL2.lib or SDL2main.lib, go to Part 4, step 1, sub-step Configure "Additional Library Directories" and follow instructions. Also to sub-step Configure "Additional Dependencies".
    • "entry point must be defined" go to Part 4, step 1, sub-step Configure "System" and follow instructions.
  2. 2
    In thrown window with X in red circle. If it is said, file SDL2.dll is missing, go to part 4, step 2, Copy "SDL2.dll" file and paste into project-folder and follow instructions.
  3. 3
    For other errors. If you cannot correct them, close Visual Studio > delete project folder Project-0 which lives in C:\GL > open Visual Studio > repeat set up from Part (Method) 3. Good job.

Method 7 of 10:
Creating Project with SDL Template

  1. 1
  2. 2
    Create project
    • Click File > New > Project....
      • In Create a new project wizard scroll down the list of templates and select SDL > click Next.
      • In Configure your new project wizard, in "Project name" text field type Project-1. Location should be C:\GL. Be sure Place solution and project in the same directory is checked. Click Create.
    • On Solution Explorer, double click Source Files > double click Source.cpp.
      • If its code appears, it's okay. If does not, right click on Source.cpp that is below Source Files > click Exclude From Project, and create new Source.cpp file.
      • If a Wizard appears saying: File 'C:\GL\Project-1\Source.cpp' already exists in the project, go to this path and delete the file Source.cpp. Click OK on the Wizard and then click Add on the Add New Item - Project-1 window. Now on Solution Explore, below Source Files, you have the new Source.cpp file.
    • Navigate C: > GL > Project-0 > click file "SDL2.dll" > right click > click "Copy".
    • Navigate C: > GL > Project-1 > click on empty area > right click > click "Paste".
    • Now a copy of the file "SDL2.dll" is in folder "Project-1" among "Source.cpp" and other 4 files.
    • In "Solution Explorer" double click Source Files > Source.cpp. Delete code and paste a new one. Hit Ctrl+F5.
  3. 3
    Use your template. Creating a project with an SDL Template is just like creating an ordinary C++ project, but with one more step:
    • The file "SDL2.dll" should be copied from a previous SDL project-folder and pasted into new project-folder.

Method 8 of 10:
Create project to target x64 platform

  1. 1
    Create empty project as above with name Project-64 and add Source.cpp file.
  2. 2
    Project-64's Property Pages main settings. Go to "Solution Explorer" > right click on the name of your project that is Project-64 > select "Properties". In Platform: entry, choose x64 > Click Configuration manager...
    • In Active solution platform: select x64
    • In Platform entry, x64 is automatically selected.
    • Click Close
    • Tip: Even when in Property Pages wizard, in Platform: entry, x64 is set, click Configuration manager..., and in Active solution platform: select x64.
  3. 3
    Additional Include Directories. As above, see Method 4, step 1, sub-step (1).
  4. 4
    Additional Library Directories. Open the "Linker" drop-down menu, and click "General". Click "Additional Library Directories" entry > down arrow at the end of the field > "Edit" in the drop-down menu.
    • At the top of the "Additional Library Directories" wizard, click the first icon > click ... next to the text box.
    • In the "Select Directory" wizard, navigate C: > GL > SDL2, and double click "lib" folder, followed by clicking "x64" folder. The "Folder" is "x64". Click Select folder on "Select Directory" window and OK on "Additional Library Directories" wizard.
  5. 5
    Additional Dependencies. As above, see Method 4, step 1, sub-step (3).
  6. 6
    Subsystem. As above, see Method 4, step 1, sub-step (4).
  7. 7
    Copy "SDL2.dll" file and paste into Project-64. In Windows's "File Explorer" navigate to
    • C: > GL > SDL2 > lib > x64. In "x64" folder click "SDL2.dll" file > right-click > "Copy".
    • C: > GL > Project-2. Right-click on empty area in "Project-64" folder, and select "Paste".
  8. 8
    Test your project and correct errors if any. As with targeting platform x86. See Methods 5 and 6. Good job.
    • Tip: Even if in Property Pages main settings it is Platform: x64, click Configuration manager... and in Active solution platform: select x64.
  9. 9
    Create template. As above method 7.
    • TIP: In every project you create with it, select x64 (next to Debug) in Visual Studio's GUI.

Method 9 of 10:
Compiling Source Code with CMake and Visual Studio

Compiling a library from the source code guarantees that the resulting library is perfectly tailored for your CPU/OS, a luxury pre-compiled binaries don't always provide. It is also important that binaries you get target x64 platform.

  1. 1
    Highlight what you expect to do. For example see picture above.
  2. 2
    Create folder GL. In Windows File Explorer, in directory C:\, right click on empty area > select New > Folder > type: GL > hit Enter.
  3. 3
    Download CMake. Right-click on following address and select Open Link in New Window https://cmake.org/download/. Scroll down the page (see image above). Under "Latest Release (today is 3.16.2)" on the second "Platform" list, find "Windows win64-x64.ZIP" and click the beside entry (today is cmake-3.16.2-win64-x64.zip > in opening wizard select Save file.
    • Copy and unzip the zip folder.
      • In downloading window, click folder > right click > in drop-down menu select Copy.
      • Navigate to directory C:\ > GL > right click > select Paste.
      • When copying and unzipping (extracting files) is finished, double click unzip folder cmake-3.16.2-win64-x64 (or latest version) > bin > inside you should see CMake's logo next to file name cmake-gui > double click this file. If wizard "Windows protect your PC" appears, click More information > Run anyway. Now on your screen you have CMake GUI.
      • Each time you need CMake, navigate to C:\ > GL > cmake-3.16.2-win64-x64 (or latest version) > bin > double click file cmake-gui (the one with CMake's logo).
  4. 4
    Download source code. Right-click on following address and select Open Link in New Window http://libsdl.org/download-2.0.php. Under Source Code select the first option, today is SDL2-2.0.10.zip.
    • Copy and unzip folder.
      • In downloading window click zip folder SDL2-2.0.10.zip (or latest version) > right click > select Copy.
      • Navigate to C:\ > GL > right click > select Paste.
      • Now in directory C:\GL, you have unzip folder SDL2-2.0.10. Click twice on its name > delete name > type: SDL > hit Enter.
    • Add the source code. In the CMake GUI first text field, copy C:/GL/SDL and paste.
    • Add where to build the binaries. In the second text field, copy C:/GL/SDL/build and paste.
    • Configure and generate. In CMake GUI, click Configure > in wizard Create Directory click Yes > click Finish.
    • When, in CMake GUI, you read: "Configuring done", click Generate. You should read: "Generating done".
  5. 5
    Build your solution.
    • Navigate to C: > GL > SDL > build. Double click "SDL2.sln", or "SDL2", or "ALL_BUILD.vcxproj". An instance of Visual Studio appears. In the main menu, click "Build" > "Build Solution".
    • Wait till you read the last line in "Output" window: ========== Build: 5 succeeded, 0 failed, 0 up-to-date, 2 skipped" ==========
      • TIP: Number of "succeeded" changes in SDL2 versions. Today (28-1-2020) is 5.
  6. 6
    Create an empty project. Click 'File > New > Project… > Create a new project > Empty project > Next.
    • In Project name text box type: pb-0.
    • Next to Location text box, click ....
    • Navigate to C:\ > GL > Click Select a folder. The Location is C:\GL.
    • Check box Place solution and project in the same directory.
    • Click Create.
  7. 7
    Add your source file to the Project. In Solution Explorer wizard, right click the Source Files folder (the last one) > click Add > New Item…
    • In the Add New Item - pb-0 window, click C++ File (.cpp) (the first one) from the middle of the window. In the Name text box, type Main.cpp.
    • The Location is C:\GL\pb-0.
    • Click the Add button. The file will open in the main text editor but leave it blank for now.
  8. 8
    Configure project's Properties. In Solution Explorer wizard, right click Project's name that is pb-0 > select Properties.
    • (1) pb-0 Property Pages main menu. In Platform entry select x64 > click Configuration Manager....
      • In Active solution platform: select x64.
      • In Platform entry, x64 is automatically selected.
      • Click Close.
    • (2) Additional Include Directories. Click C/C++ > General > In beside menu select the first one, Additional Include Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ...
      • Navigate to C: > GL > SDL > include > click include > click Select a folder > click OK.
    • (3) Additional Library Directories. Double click Linker > click General > Additional Library Directories > click the down arrow at the end of the field > click Edit... > first icon > three dots ....
      • Navigate to C: > GL > SDL > build > Debug > click Select a folder > click OK.
    • (4) Additional Dependencies. In Linker drop-down menu select Input > in beside menu select the first one, Additional Dependencies > click the down arrow at the end of the field > Edit... > copy opengl32.lib; SDL2maind.lib; SDL2d.lib and paste in Additional Dependencies wizard's upper-most text box > click OK.
    • (5) Set System to SubSystem CONSOLE. In Linker drop-down menu select System > in beside menu select the first one, SubSystem > click the down arrow at the end of the field > select Console (/SUBSYSTEM:CONSOLE). Click Apply and OK.
  9. 9
    Copy SDL2d.dll file and paste in pb-0 project. Navigate to C: > GL > SDL > build > Debug, and copy (by right click > Copy) file SDL2d.dll.
    • Navigate to C: > GL > pb-0, and paste. Now in project folder pb-0 you have DLL file SDL2d.dll among Source.cpp and other 4 files created by Visual Studio.
  10. 10
    Test your project and correct errors if any. Follow Methods 5 and 6.
  11. 11
    Create template. Follow Method 7. Every time you create project with this template, select x64 in Visual Studio GUI's main menu. Good job.

Method 10 of 10:
Choosing Set Up

  1. 1
    In this tutorial you learn 3 was to set up SDL in Project with Visual Studio.
    • Set up binaries x86 (32 bits). It's the easiest. You should start learning set up from here.
    • Set up binaries x64 (64 bits). It targets x64 platform. Choose it only when you have specific reason for doing so.
    • Compile SDL source, and set up in project. Targets x64 too.The most difficult. The best though.

Community Q&A

Search
Add New Question
  • Question
    What does unresolved external symbol "referenced in" mean?
    Bryan Hadland
    Community Answer
    An unresolved external symbol means that you have not setup the project fully. By this I mean make sure you have linked against the library that your using.
  • Question
    I'm using 64-bit Windows. Method 4, Step 2, "Configure the linker 'Additional Library Directories'," mentioned selecting x86. Since I'm using 64-bit, can I choose x64?
    Community Answer
    You can use x86 platform (32 bits) with Windows 64-bit. However if you need x64 do this: Create a new empty project. Follow the article's instructions with these changes: 1. In Project's Property Pages wizard 1.1. In ''Platform:'' entry, choose ''x64" 1.2. Click [Configuration manager...], 1.2.1. In ''Active solution platform:'' select x64, 1.2.2. In ''Platform'' entry choose x64. Click [Close]. 1.3. In "Linker" > "General" > "Additional Librariy Directories'' > down arrow at the end of the field > Edit.. > three dots > in "Select Directory" window, navigate to C:\SDL\SDL2\lib\x64, and click [Select a folder]. 2. In Windows File Explorer navigate to C:\SDL\SDL2\lib\x64 and copy file SDL2.dll. Paste in your project folder.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit

Tips

  • You can create a folder in folder C:\GL for place in there your projects. When you create a project select this folder for "Location".
    Thanks!
  • General way for configure Additional Include Directories is that, after clicking first icon, click three dots ..., navigate to the folder where .h file(s) live(s) (C: > SDL > SDL2 > include, in this tutorial) and click Select a folder.
    Thanks!
  • General way for configure Additional Library Directories is that, after clicking first icon, click three dots ..., navigate to the folder where .lib file(s) live(s) (C: > SDL > SDL2 > lib > x86, in this tutorial) and click Select a folder.
    Thanks!
  • General way for configure Additional Dependencies is that,
    • In File Explorer navigate to folder where .lib file(s) live(s) (C: > SDL > SDL2 > lib > x86, in this tutorial), click twice on the name of each .lib file and copy (by strike Ctrl+C) the name with its extension .lib.
    • Now go to Additional Dependencies wizard and paste it (by strike Ctrl+V). Type a semicolon (;).
    • If you want configure OpenGL with your project add opengl32.lib.
    Thanks!
  • If dll files are needed, then, in every project you create - even with template created by project including dll file - you should copy dll file(s) from libraries or previous project and paste in the new project.
    Thanks!

Submit a Tip
All tip submissions are carefully reviewed before being published
Thanks for submitting a tip for review!

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 17 people, some anonymous, worked to edit and improve it over time. This article has also been viewed 64,886 times.
How helpful is this?
Co-authors: 17
Updated: February 24, 2020
Views: 64,886
Thanks to all authors for creating a page that has been read 64,886 times.

Is this article up to date?