Setting up SDL in Pelles C
In order to use SDL in Pelles C, you first need to set up the SDL library so that it can be used. This is a simple process. Just follow the steps below. If you have any problems, please log in to our forum and drop us a note. We'll see what we can do to help you.
Special thanks to Ngan Lo for supplying instructions on how to set up SDL in an efficient way and frankie on the Pelles C forum for helping me get SDL working with Pelles C on my own machine after it mysteriously stopped working!!
- Download SDL Go to the SDL webpage, click on the latest version of SDL (version 1.2 at the time of writing) in the download section of the menu on the left hand side of the page. In the source code section, download the source code zip file and in the development libraries, download the Win32 (Visual C++ 6.0) zip file.
- Create a Pelles C Project Click File->New->Project. Select "Win32 Static Library (.lib)" and call it sdlmain. Take note of the location of the project directory that will be created.
- Extract the SDL source code Inside the source code zip file you will find a src\main\win32 directory. Copy the file SDL_win32_main.c to the new Pelles C project directory you created.
- Extract the Include Files Copy all the files from the include directory of the source code zip file into Pelles C's Include directory.
- Add sdl_win32_main.c to the Project Click Project->Add files to project, and select the file sdl_win32_main.c.
- Set Compiler Options Go to Project->Project Options->Compiler and tick the box that says "Enable Microsoft Extensions" and set "Calling conv" to "__cdecl" in the drop down box.
- Build the Library Click Projects->Build sdlmain.lib. It will sit there for some time building (though it may look like nothing is happening). Eventually in the pane at the bottom it will say "Done".
- Copy the .lib File In your sdlmain project directory, you will now find the library you have just built (sdlmain.lib). Copy this to Pelles C's Lib directory.
- Copy the other Libraries Unzip the developers libraries zip file and copy the file sdl.lib to Pelles C's Lib directory. Copy the file sdl.dll to the Pelles C Bin directory. These files are in the lib folder of the zip file. Again you are probably better off extracting the whole zip file and then just copying the files you need.
- Remove old copies of SDL.DLL from your machine. Do a search of your Windows directory on you machine, and all its subdirectories, especially Windows\system and ensure there are no old copies of SDL.DLL there as these will interfere with the copy that you have placed in your PellesC\Bin directory. If you need SDL for other things, place the dll file in the Windows\system directory instead of PellesC\Bin.
For those wishing to use SDL in linux, using the gcc C compiler, this is possible, and someone has helpfully left instructions in our forum in the C Programming section on how to do this. Whilst we haven't tested these instructions, they certainly look correct.