Friday, June 18, 2010

Build SDL Library for PellesC and Use it in SDL project

Download SDL source and SDL runtime library from SDL homepage.

Extract all header files in include folder from SDL source package into PellesC installation directory, include/sdl sub folder

Extract SDL.dll to PellesC installation folder, bin sub folder.
run command polib sdl.dll /OUT:sdl.lib to create the SDL.lib file
copy SDL.lib to PellesC installation folder, lib sub folder.

To Build Library:
  • Create Pelles C project, select "Win32 Static Library (.lib)" project type, project name set as "sdlmain"
  • Extract SDL_win32_main.c file from src/main/win32 directory, and add this file into the new project
  • Set the include directory to include include/sdl  directory.
  • Set compiler option: 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 library file
  • Copy the output file sdlmain.lib into PellesC installation directory, lib sub folder.

TO Use SDL Library In Project:
  • Create a Project
  • Create a new project (either a Win32 Console or Win32 Program).
  • Include sdl.h
  • Create your sdl program (i.e. write your source code), making sure that you #include <sdl.h>
  • Set Compiler Options
  • In Project->Project Options->Compiler, set the __cdecl calling convention from the drop down list. Also select the "Enable Microsoft extensions" option.
  • Set Linker Options
  • In Project->Project Options->Linker (if this doesn't show up you haven't created a project properly yet), add "sdl.lib" and "sdlmain.lib" (just write the filenames with a space separating them) to the list of "Library and object files".


No comments: