Tuesday, September 14, 2010

How to setup SDL-Library for Visual Studio Compiler

  1. On the SDL download page, get the latest version of the Windows-VC development libraries.
  2. If you want to use the SDL_mixer library (for sound and music), download the Windows-VC development libraries for SDL_mixer.
  3. Uncompress the SDL and SDL_mixer libraries to your local drive.
  4. Consolidate the SDL includes and libraries with the SDL_mixer includes and libraries, so that they're all in a single set of \include and \lib folders. It's easier this way!
  5. Launch Visual Studio .NET, but do not open a project or solution.
  6. From the Tools menu, select Options...
  7. In the tree view, click on Projects and then select VC++ Directories.
  8. In the Show directories for box, select Include files.
  9. Click the new-folder icon, and browse to the \include directory where you consolidated your SDL and SDL_mixer header files.
  10. In the Show directories for box, you now need to select Library files.
  11. Click the new-folder icon, and browse to the \lib directory where you consolidated your SDL and SDL_mixer library files.
  12. Click OK.
Your build environment is now set up, and VC++.NET will now know where to find the SDL and SDL_mixer headers and libraries. To create an SDL project, perform the following steps.
  1. Launch Visual Studio .NET and from the File menu, select New and then Project...
  2. In the tree view, expand Visual C++ Projects and select Win32.
  3. If you don't want a console window to appear when your program is executed, select Win32 Project. Otherwise, select Win32 Console Project. Give your project a name and location, then click OK.
  4. From the Project menu, select Properties... at the bottom of the menu.
  5. In the tree view, expand C/C++ and select Code Generation.
  6. Set the Runtime Library value to Multi-threaded DLL or Multi-threaded Debug DLL.
  7. We're still in the Properties dialog. In the tree view, now expand Linker and select Command Line.
  8. In the Additional Options field, enter SDL.lib SDLmain.lib and if you are using SDL_mixer, also add SDL_mixer.lib.
  9. VC++ is now set up. You may add your SDL source code to the project, and proceed as normal.
NOTES:
  • The SDL Windows FAQ states that this step is necessary because, "SDL is dynamically linked with the multi-threaded version of the Microsoft Visual C runtime."
  • If you plan on running the VC++ debugger with SDL you will have to pass the value SDL_INIT_NOPARACHUTE to SDL_Init in order for debugging to succeed!
  • When you compile your executable, you will need to copy the SDL.dll and SDL_mixer.dll files into the same folder as the EXE. If these DLLs are missing, when the program is executed you will be given an error message regarding the needed DLLs.

No comments:

Post a Comment