slouken@0: slouken@521: slouken@521: Using SDL with Microsoft Visual C++ slouken@521: slouken@521: slouken@521:

slouken@521: Using SDL with Microsoft Visual C++ 5,6 and 7 slouken@521:

slouken@521:

slouken@521: by Lion Kimbro and additions by slouken@521: James Turk slouken@521:

slouken@521:

slouken@521: You can either use the precompiled libraries from slouken@521: the SDL Download web site , or you can build SDL yourself. slouken@521:

slouken@521:

slouken@521: Building SDL slouken@521:

slouken@521:

slouken@521: Unzip the VisualC.zip file into the directory that contains this slouken@1131: file (VisualC.html). slouken@521:

slouken@521:

slouken@521: Be certain that you unzip the zip file for your compiler into this slouken@521: directory and not any other directory. If you are using WinZip, be careful to slouken@521: make sure that it extracts to this folder, because it's slouken@521: convenient feature of unzipping to a folder with the name of the file currently slouken@521: being unzipped will get you in trouble if you use it right now. And that's all slouken@521: I have to say about that. slouken@521:

slouken@521:

slouken@1131: Now that it's unzipped, go into the VisualC slouken@521: directory that is created, and double-click on the VC++ file "SDL.dsw" slouken@521: ("SDL.sln"). This should open up the IDE. slouken@521:

slouken@521:

slouken@521: You may be prompted at this point to upgrade the workspace, should you be using slouken@521: a more recent version of Visual C++. If so, allow the workspace to be upgraded. slouken@521:

slouken@521:

slouken@521: Build the .dll and .lib files. slouken@521:

slouken@521:

slouken@521: This is done by right clicking on each project in turn (Projects are listed in slouken@521: the Workspace panel in the FileView tab), and selecting "Build". slouken@521:

slouken@521:

slouken@4052: If you get an error about SDL_config.h being missing, you should slouken@4052: copy include/SDL_config.h.default to include/SDL_config.h and try again. slouken@4052:

slouken@4052:

slouken@521: You may get a few warnings, but you should not get any errors. You do have to slouken@521: have at least the DirectX 5 SDK installed, however. The latest slouken@521: version of DirectX can be downloaded or purchased on a cheap CD (my slouken@521: recommendation) from Microsoft . slouken@521:

slouken@521:

slouken@521: Later, we will refer to the following .lib and .dll files that have just been slouken@521: generated: slouken@521:

slouken@521: slouken@521:

slouken@521: Search for these using the Windows Find (Windows-F) utility, if you don't slouken@521: already know where they should be. For those of you with a clue, look inside slouken@521: the Debug or Release directories of the subdirectories of the Project folder. slouken@521: (It might be easier to just use Windows Find if this sounds confusing. And slouken@521: don't worry about needing a clue; we all need visits from the clue fairy slouken@521: frequently.) slouken@521:

slouken@521:

slouken@521: Creating a Project with SDL slouken@521:

slouken@521:

slouken@521: Create a project as a Win32 Application. slouken@521:

slouken@521:

slouken@521: Create a C++ file for your project. slouken@521:

slouken@521:

slouken@521: Set the C runtime to "Multi-threaded DLL" in the menu: Project|Settings|C/C++ slouken@521: tab|Code Generation|Runtime Library . slouken@521:

slouken@521:

slouken@521: Add the SDL include directory to your list of includes in the slouken@521: menu: Project|Settings|C/C++ tab|Preprocessor|Additional include directories slouken@521: . slouken@521:
slouken@521: VC7 Specific: Instead of doing this I find it easier to slouken@521: add the include and library directories to the list that VC7 keeps. Do this by slouken@521: selecting Tools|Options|Projects|VC++ Directories and under the "Show slouken@521: Directories For:" dropbox select "Include Files", and click the "New Directory slouken@521: Icon" and add the [SDLROOT]\include directory (ex. If you installed to slouken@521: c:\SDL-1.2.5\ add c:\SDL-1.2.5\include). Proceed to change the slouken@521: dropbox selection to "Library Files" and add [SDLROOT]\lib. slouken@521:

slouken@521:

slouken@521: The "include directory" I am referring to is the include folder slouken@521: within the main SDL directory (the one that this HTML file located within). slouken@521:

slouken@521:

slouken@521: Now we're going to use the files that we had created earlier in the Build SDL slouken@521: step. slouken@521:

slouken@521:

slouken@521: Copy the following files into your Project directory: slouken@521:

slouken@521: slouken@521:

slouken@521: Add the following files to your project (It is not necessary to copy them to slouken@521: your project directory): slouken@521:

slouken@521: slouken@521:

slouken@521: (To add them to your project, right click on your project, and select "Add slouken@521: files to project") slouken@521:

slouken@521:

Instead of adding the files to your project it is more slouken@521: desireable to add them to the linker options: Project|Properties|Linker|Command slouken@521: Line and type the names of the libraries to link with in the "Additional slouken@521: Options:" box.  Note: This must be done for each build slouken@521: configuration (eg. Release,Debug).

slouken@521:

slouken@521: SDL 101, First Day of Class slouken@521:

slouken@521:

slouken@521: Now create the basic body of your project. The body of your program should take slouken@521: the following form: slouken@521:

slouken@521: #include "SDL.h"
slouken@0: 
slouken@0: int main( int argc, char* argv[] )
slouken@0: {
slouken@0:   // Body of the program goes here.
slouken@0:   return 0;
slouken@0: }
slouken@0: 
slouken@521: slouken@521:

slouken@521:

slouken@521: That's it! slouken@521:

slouken@521:

slouken@521: I hope that this document has helped you get through the most difficult part of slouken@521: using the SDL: installing it. Suggestions for improvements to this document slouken@521: should be sent to the writers of this document. slouken@521:

slouken@521:

slouken@521: Thanks to Paulus Esterhazy (pesterhazy@gmx.net), for the work on VC++ port. slouken@521:

slouken@521:

slouken@521: This document was originally called "VisualC.txt", and was written by slouken@521: Sam Lantinga. slouken@521:

slouken@521:

slouken@521: Later, it was converted to HTML and expanded into the document that you see slouken@521: today by Lion Kimbro. slouken@521:

slouken@521:

Minor Fixes and Visual C++ 7 Information (In Green) was added by James Turk slouken@521:

slouken@521: slouken@0: