Compiling SDL with MinGW on Window 8.1?

Started by
3 comments, last by wintertime 8 years, 8 months ago

I am new to SDL and to cross-platform in general.

I want to recompile SDL just to make sure I can eventually change it if needed, and then a few demos on my Windows 8.1 development machine.

I would also like to use open source compilers if possible so I installed codeblocks IDE + MinGW and tried to compile the SDL 2.0.3 source code.

It first failed saying it needed ddraw.h so I installed 'Direct X SDK' (I only plan on using OpenGL but I am told that DirectX is required for joystick input) but then I found on a forum that it was replaced by 'Windows 8.x SDK' , so I installed 'Windows 8.1 SDK' and added the include directories but now I get '...\Include\um\winnt.h|938|error: #error Must define a target architecture.' so I am starting to wonder if using MinGW is a valid way to compile SDL on Windows.

I looked at some of the wiki on codeblocks about recompiling SDL but they are 10+ years old:

http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks

I also looked at some info on the SDL site but they mention an August 2007 DirectX SDK so it does not look too recent either:

http://www.libsdl.org/extras/win32/cross/README.txt

Advertisement
Don't use vanilla MinGW. Life is easier with a distribution like TDM-GCC, which is based on MinGW-w64. I comes with all of the DirectX headers and libraries you'll need. I also recommend installing MSYS2 and working through that rather than the Windows cmd shell, if you aren't already.

Furthermore, it's generally a bad idea to mix things compiled via the Microsoft toolchain with MinGW, such as the binaries found in the Windows SDK. MinGW can link dynamically with DLLs if you pass them along, but attempting to link with static or import libraries is asking for trouble. Any third-party libraries you use should generally be compiled with MinGW as well.

Thanks for your help!

I installed TDM-GCC as you suggested. The compilation went a lot farther but now I get:
...\SDL2-2.0.3\src\audio\xaudio2\SDL_xaudio2.c|95|fatal error: xaudio2.h: No such file or directory

So I tried adding the 'Windows 8.1 SDK' which does contain xaudio2.h but then it seems to get stuck with the original problem:
...\Windows SDK 8.1\Include\um\winnt.h|147|error: #error "No Target Architecture"

Not sure if Msys2 is required to rebuild SDL or if MinGW is enough.

I agree it looks like trouble to mix Microsoft libs with MinGW but SDL is including directX headers and Microsoft headers can include whatever they like (e.g. windows.h, winnt.h).

How are you building? CMake should be looking for xaudio2.h and, failing to find it, configure the makefile so that it isn't enabled. I just tried it out using the Windows cmd prompt (I normally build through MSYS) to be sure it works for me:

cd sdl-source-dir
mkdir build
cd build
CMake -G"MinGW Makefiles" ..

-->CMake spits out a lot of stuff here, including:
-- Looking for d3d9.h
-- Looking for d3d9.h - not found
-- Looking for d3d11_1.h
-- Looking for d3d11_1.h - not found
-- Looking for ddraw.h
-- Looking for ddraw.h - not found
-- Looking for dsound.h
-- Looking for dsound.h - not found
-- Looking for dinput.h
-- Looking for dinput.h - not found
-- Looking for xaudio2.h
-- Looking for xaudio2.h - not found

---> Then, when it finishes:
mingw32-make
I get both static and dynamic versions of SDL successfully compiled as a result. I don't know why CMake isn't finding the DX headers, though, as I'm looking at most of them in Windows Explorer, but that's beside the point.

You may need to write and install a FindXXX.cmake script or use cmake-gui and manually change some variables, because cmake is not very intelligent and there are no standardised paths on Windows for finding libraries.

This topic is closed to new replies.

Advertisement