Frequently Asked Questions - Win32

Last updated: Fri Dec 8

Table Of Contents

 


Q: Does it work?

A: Yes. SDL supports VC++ 5.0 and Cygnus Mingw32 under Win95 ©, Win98 ©, and Windows NT ©.

SDL takes advantage of DirectX hardware acceleration when it is available, but falls back to the standard Win32 services if DirectX is not installed.


Q: Can I build SDL for Windows CE?

A: SDL is not officially supported on Windows CE, and doesn't build yet.

You can play with building SDL for WinCE if you have the WinCE SDK and grab the following files:
http://www.libsdl.org/cvs/WinCE.txt
http://www.libsdl.org/cvs/WinCE-SDL.zip
The text file contains a list of the missing functionality in WinCE, and the ZIP file contains a build project for SDL on WinCE for the MIPS processor. Just unpack it in the main SDL directory.

The code almost compiles. The audio doesn't work because WinCE 2.1 doesn't contain semaphore support, and the video doesn't work because there doesn't seem to be a way to set the palette in a DIBSection. I can't test this code, so I'm relying on you all for coding support.


Q: How do I use SDL with a Linux cross-compiler?

A: Read the file "README.Win32" included with the source distribution.


Q: How do I add SDL to my cross-compiled project?

A: Adding SDL to your cross-compiled project is the same as adding it to a normal Linux project. See the Linux FAQ for more details.


Q: How do I use SDL with Visual C++?

A: Read the file "VisualC.html" included with the source distribution.


Q: How do I add SDL to my Visual C++ project?

A:

Make sure that you include <SDL/SDL.h> in the source file that contains your main() function. If your program contains WinMain(), you should remove it, as it is not portable *.

Go to your project settings, and add the include directory in the SDL distribution to your list of additional include directories. Also add SDL.lib and SDLmain.lib from the SDL distribution to your list of files for the project.

* If you really need WinMain() for some reason, look at the SDL source code for the Win32 version of SDL_main.cpp, and mimic that as much as possible, and then leave SDLmain.lib out of your project.


Q: I get link errors relating to MSVCRT.LIB or LIBC:
LINK : warning LNK4098: defaultlib "XXX" conflicts with use of other libs; use /NODEFAULTLIB:library

A:SDL 1.1.5 and newer is dynamically linked with the multi-threaded version of the Microsoft Visual C runtime. You need to edit your project settings, go to the C++ language tab, change the listbox to "Code Generation" settings, and then change the runtime library to "Multi-threaded DLL".
Older versions of SDL are statically linked with the C runtime, so for those you should change the code generation to "Multi-threaded", without any DLL.


Q: How do I use SDL with free Borland C++?

A: This howto was contributed by Chris Dion:

Here's a step-by-step run through of what I did. I haven't used .dll's and such before, so you'll have to excuse me if I'm not using the right terminology.

  1. Run the IMPLIB utility on SDL.DLL to make a new SDL.LIB import library. Use the -a and -c switches.
  2. You still need the SDL_MAIN.LIB file, so that you don't need to define WinMain() and all that junky windows stuff. You have no .dll file to build this .lib from, and COFF2OMF creates a empty .lib (you can check with TDUMP, another utillity that comes with the compiler). Get the Win32 version of the SDL_main.c file from the source, and dump it in with the rest of your project,
  3. Compile your source (including SDL_main.c) into object files using BCC32 with the following compiler options:
      -c (Don't link)
      -tW (Create windows app)
      -DWIN32 (Define WIN32, this is needed in the SDL_main.h file, and maybe others)
  4. Link the.obj files together using ILINK32 with the following options:
      -aa (Create windows app, sounds redundant, but...)
      -Tpe (Target = windows exe)
      -c (case sensitive linking, may be the default...)
    and the following additional files (order is important)
    • sdl.lib (created in step 1)
    • import32.lib
    • c0w32.obj
    • cw32.lib

If all goes well, you should have a working .exe file. The help files that come with the command line tools are missing detailed descriptions of the various compiler/linker switches. You can download a complete help file from the Borland ftp site here:
ftp://ftp.borland.com/pub/bcppbuilder/techpubs/bcb5/b5std.zip


Q: How do I use SDL with Borland C++ Builder?

A: Here are some instructions and examples contributed by Alessandro Porcu: SDL_borland3.zip

Martin Bickel writes:
For both Watcom C/C++ and Borland C/C++ the compiler option that makes enums having the size of an int must be enabled. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).


Q: How do I use SDL with native Mingw32?

A: Grab the native Mingw32 tools from: http://www.libsdl.org/Xmingw32/
Unpack them in C:\ and run the included mingw32.bat script. This will launch the bash shell with the environment set up for UNIX style builds. Now just follow the standard UNIX build procedures (./configure; make; make install)


Q: How do I use SDL with Cygwin32?

A: Apparently Cygwin32 can be used to build applications with the native Win32 APIs, but I've never tried it, and nobody else has submitted patches for it. I recommend the Mingw32 build toolchain available from: http://www.libsdl.org/Xmingw32/


Q: I get "Undefined reference to 'SDL_main'" ...

A: Make sure that you are declaring main() as:

#include "SDL.h"

int main(int argc, char *argv[])
You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly.


Q: I get "Undefined reference to 'WinMain@16'" ...

A: You need to link with the output of sdl-config --libs:
-lmingw32 -lSDLmain -lSDL -mwindows
The order of the options is very important.