Set up Visual Studio 2022 C++ for SDL2 for Windows

Please pin this.

I was having difficulties in setting up Visual Studio. I have tried different SDL setup tutorials.
Most are confusing
SDL2-devel-2.30.0-VC.zip should include a solution/project file .

So I wrote up instructions to Set up Visual Studio 2022 C++ and notes. Any additions is welcome.

//*********************

SDL2 setup with Visual Studio 2022

Visual Studio 2022 with Desktop development with C++ installed.
Windows 10.

Download SDL2-devel-2.30.0-VC.zip from Release 2.30.0 · libsdl-org/SDL · GitHub

Unzip SDL2-devel-2.30.0-VC.zip .
Copy contents of SDL2-2.30.0 folder to c:\SDL2

Windows 10 Click start type environment. Edit the system environment variable.
Set Environment Variable under System Variables. Add new SDLROOT path C:\SDL2

Create new project.
Select Windows Desltop Application C++ Windows Desktop
Enter Project name
Enter location for Project
Porject will create a folder with the name of Project Name.
Foldername/Project name Copy you files here.

Solution->Header files Add .h files
Solution->Source Files Add .c or .cpp files
Solution->Resource add SDL2.dll
Right click on SDL2.dll
SDL2.dll Property Pages->General->Item Type Select Copy FIle. This will copy SDL2.dll to your
vxcproj folder /Debug The .exe file needs SDL2.dll to run.

For debugging set a breakpoint at ini main() . Otherwize the program will not enter the program and stop

Configuration Debug Platform Win32(x86)
Property Pages->Configuration Properties->Advanced->Character Set Use Unicode Character Set
Property Pages->Configuration Properties->Advanced->Library Directories $(SDLROOT)\include\lib\x86
Property Pages->Configuration Properties->VC++ Directories add pathname to any extra inlude folders
You can also add
$(SolutionDir)\include;
$(SolutionDir)

Property Pages->Configuration Properties->C/C+±>General->Additional Include Directories $(SDLROOT)\include
Property Pages->Configuration Properties->C/C+±>General->SDL Checks (Delete whatever is there )
/sdl will complain about legacy items like iota, kbhit, memset
Property Pages->Configuration Properties->C/C+±>Optimization->Optimization Disabled (/Od) (No optimization)
Property Pages->Configuration Properties->C/C+±>Preprocessor->Preprocessor Definitions
WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
Property Pages->Configuration Properties->Linker->General->Additional Library Directories $(SDLROOT)\lib\x86
Property Pages->Configuration Properties->Linker->Input SDL2.lib;SDL2main.lib;
Property Pages->Configuration Properties->Linker->System->SubSystem Windows (/SUBSYSTEM:WINDOWS)

Visual Studio 2022

Toggle constexpr
Tools->Options->Text Editor->C/C+±>View->Code Squigles Macros Convertible to constexpr

int main() Compiling and linking in C++ gives unresolved external symbol _SDL_main
use int main(int argc, char* argv)

//*********** END

1 Like