# SDL 2.0 compilation with Visual Studio 2015

**URL:** <https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577>\
**Category:** SDL Development\
**Created:** [October 28, 2015, 2:56am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577 "2015-10-28T02:56:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Ludwig](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_ludwig/32/4016_2.png) [@David\_Ludwig](https://discourse.libsdl.org/u/David_Ludwig)\
**Post date:** [October 28, 2015, 2:56am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/1 "2015-10-28T02:56:24Z")

</div>

rotanov wrote:

> The first post errors occurred on Windows 7 system with Visual Studio 2015.  
> On another system (Windows 8 Visual Studio 2015) I got lots of those:
> 
> > Severity Code Description Project File Line  
> > Error C2011 ‘\_XINPUT\_BATTERY\_INFORMATION’: ‘struct’ type redefinition [D:\dev\engine\build\sdl\src\sdl-build\SDL2.vcxproj] sdl d:\dev\engine\3rd\sdl\src\core\windows\SDL\_xinput.h 122
> 
> Maybe related to this commit [SDL - added new SDL\_JoystickCurrentPowerLevel() API that returns the … · spurious/SDL-mirror@bf785c7 · GitHub](https://github.com/spurious/SDL-mirror/commit/bf785c766bdcdf6ad498123ae80d132a7192b10d)

I can’t speak definitively on the Win7 error. It kind-of looks like you might be mixing debug-mode and release-mode SDL dlls, but I could be wrong there.

On the Win8 error, that looks like it might be a bug in SDL, one where the commit you referenced (also referenced on the official SDL hg server, via [SDL - added new SDL\_JoystickCurrentPowerLevel() API that returns the … · libsdl-org/SDL@a0c4b56 · GitHub](https://hg.libsdl.org/SDL/rev/26b595dea221) ), caused builds against certain versions of the Windows SDK to fail. I get the same error on WinRT, after having updated one of my own repos to the latest SDL code (from [hg.libsdl.org](http://hg.libsdl.org)). From briefly looking at the copy of the Windows SDK I have, it looks like the Win8+ SDKs have a few identical type declarations, which MSVC is unable to reliably resolve.

If I can find time in the next few weeks, I can take a stab at providing a patch (to Sam, Ryan, etc.), but make no guarantees. I don’t have an actively-working Win7 dev system anymore though, so I wouldn’t be able to test building there. 😑

– David L.

---

<div class="post-metadata">

**Author:** ![David\_Ludwig](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_ludwig/32/4016_2.png) [@David\_Ludwig](https://discourse.libsdl.org/u/David_Ludwig)\
**Post date:** [October 28, 2015, 3:13am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/2 "2015-10-28T03:13:04Z")

</div>

DLudwig wrote:

> If I can find time in the next few weeks, I can take a stab at providing a patch (to Sam, Ryan, etc.), but make no guarantees. I don’t have an actively-working Win7 dev system anymore though, so I wouldn’t be able to test building there. 😑

I came up with a quick, largely-untested patch just now. I’ve only tested it on WinRT though. Feel free to give it a shot wherever. I suspect it may work on Win32 + MSVC 2015, but I make no guarantees on that.

[https://www.dropbox.com/s/x3dgwc0sw6cuksa/SDL\_XInput\_build\_fix\_candidate\_for\_Win8x.patch?dl=1](https://www.dropbox.com/s/x3dgwc0sw6cuksa/SDL_XInput_build_fix_candidate_for_Win8x.patch?dl=1)

Cheers,  
– David L.

---

<div class="post-metadata">

**Author:** ![Bandock](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bandock](https://discourse.libsdl.org/u/Bandock)\
**Post date:** [October 31, 2015, 10:44am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/3 "2015-10-31T10:44:56Z")

</div>

Yeah, best way to fix it is to compile the source yourself since Visual Studio 2015 made changes that broke several Visual Studio builds (anything prior to VS2015 that is). I know because I had to contend with errors like that popping up.

Hopefully, a precompiled Visual Studio 2015 build becomes available for those who don’t want to compile it themselves.

---

<div class="post-metadata">

**Author:** ![Bandock](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bandock](https://discourse.libsdl.org/u/Bandock)\
**Post date:** [November 3, 2015, 3:43am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/4 "2015-11-03T03:43:58Z")

</div>

I’ve decided to go ahead and redistribute a working Visual Studio 2015 Multi-Threaded Build (32-bit x86). It is actually compiled as a DLL (only tweaked the code generation setting), but should not require any Visual C++ 2015 Runtime Package to run.

Of course, if anyone wants me to compile a Multi-Threaded DLL build that requires the Runtime Package, let me know.

Link: [https://dl.dropboxusercontent.com/u/24250760/SDL/SDL-2.0.3%20VS2015%20MT%20Build%20(x86).zip](https://dl.dropboxusercontent.com/u/24250760/SDL/SDL-2.0.3%20VS2015%20MT%20Build%20%28x86%29.zip)

I provided the “COPYING.txt” file found with the source code distribution to make sure original credit was given.

---

<div class="post-metadata">

**Author:** ![Bandock](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bandock](https://discourse.libsdl.org/u/Bandock)\
**Post date:** [November 3, 2015, 3:46am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/5 "2015-11-03T03:46:50Z")

</div>

Addendum to my previous post: It currently uses the current stable build provided on the website. Not providing a SDL 2.0.4 build yet.

---

<div class="post-metadata">

**Author:** ![David\_Ludwig](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_ludwig/32/4016_2.png) [@David\_Ludwig](https://discourse.libsdl.org/u/David_Ludwig)\
**Post date:** [November 22, 2015, 11:27pm UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/6 "2015-11-22T23:27:49Z")

</div>

FYI, this particular bug, whereby there’s a build error in SDL\_xinput.h, should now be fixed (in the latest code from [GitHub - libsdl-org/SDL: Simple Directmedia Layer](https://hg.libsdl.org/SDL)).

Are you still seeing the other build errors?

– David L.

rotanov wrote:\> The first post errors occurred on Windows 7 system with Visual Studio 2015.

> On another system (Windows 8 Visual Studio 2015) I got lots of those:
> 
> > Severity Code Description Project File Line  
> > Error C2011 ‘\_XINPUT\_BATTERY\_INFORMATION’: ‘struct’ type redefinition [D:\dev\engine\build\sdl\src\sdl-build\SDL2.vcxproj] sdl d:\dev\engine\3rd\sdl\src\core\windows\SDL\_xinput.h 122
> 
> Maybe related to this commit [SDL - added new SDL\_JoystickCurrentPowerLevel() API that returns the … · spurious/SDL-mirror@bf785c7 · GitHub](https://github.com/spurious/SDL-mirror/commit/bf785c766bdcdf6ad498123ae80d132a7192b10d)

---

<div class="post-metadata">

**Author:** ![David\_Ludwig](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/david_ludwig/32/4016_2.png) [@David\_Ludwig](https://discourse.libsdl.org/u/David_Ludwig)\
**Post date:** [November 26, 2015, 2:24am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/7 "2015-11-26T02:24:56Z")

</div>

rotanov wrote:

> The error with `_XINPUT_BATTERY_INFORMATION` is gone now. However I’m still experiencing previous build errors, listed below for debug and release builds respectively.
> 
> > It kind-of looks like you might be mixing debug-mode and release-mode SDL dlls, but I could be wrong there.
> 
> Nope, I double checked this. 2013 is fine, 2015 results in errors. I’m using SDL as git submodule in my project therefore I’m not able to change its cmake makefiles. I’m including it in my cmake file with `ExternalProject_Add`. And I’m not sure if I can add required static libraries externally to SDL cmake project.

Sorry to hear that, and unfortunately I don’t think I can be of much help here. I am unfamiliar with SDL’s CMake setup, or CMake in general. I wouldn’t be surprised if there was either a bug in SDL’s CMake files, or perhaps CMake + VS2015, but am uncertain of this.

– David L.

---

<div class="post-metadata">

**Author:** ![Bandock](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@Bandock](https://discourse.libsdl.org/u/Bandock)\
**Post date:** [January 22, 2016, 6:54am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/8 "2016-01-22T06:54:55Z")

</div>

I have now taken down the build I put up since 2.0.4 is now available and no longer requires anytime C Runtime Package.

I even tested it myself using the provided development libraries on the main website and found it to be the compatible with Multithreaded.

---

<div class="post-metadata">

**Author:** ![rotanov](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rotanov/32/2675_2.png) [@rotanov](https://discourse.libsdl.org/u/rotanov)\
**Post date:** [January 22, 2016, 7:10am UTC](https://discourse.libsdl.org/t/sdl-2-0-compilation-with-visual-studio-2015/21577/9 "2016-01-22T07:10:53Z")

</div>

Yeah, there was a commit with fix to cmake files. I tested it a couple of days ago and it works for me just fine.
