Original Post
I don't know about you guys, but I had a dandy of a time trying to get SDL to work with VS.NET 2003. Even more frustrating was the half-formed answers I found on the GameDev forums, all which went something like: This code is from Aaron's SDL Tutorial page, which has a lot of helpful SDL info, including a VS.NET setup walkthrough. VS.NET setup Before we delve into any linker errors, let's go over how a simple setup should go: already defined in .lib Causes
Quote:Helpful, right? Anyway, in this thread, I plan to methodically go through how to set up SDL properly for VS.NET and go over solutions to the multitude of linker errors that pop up. Hopefully, with a lot of edits, linkage, and feedback, this can be become a stable resource for this prevalent and (I think) not-well-covered problem. Definitions First off, I will be setting up SDL 1.0.8 - Development Runtime with my copy of Visual Studio .NET 2003 - Academic Edition. I will be attempting to get the following piece of code to compile and run, which should display an empty window:
Noob: I'm getting Error A when trying to compile an SDL program in VS.NET. Guru: Change X, fiddle with Y, and copy-and-paste Z. Noob: OK, now I have error B... Guru: Did you fiddle with Y? Noob: Wait, I mysteriously fixed it. Thanks!
#include "SDL.h"
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "SDL Start";
int main(int argc, char **argv)
{
SDL_Init( SDL_INIT_VIDEO );
SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
SDL_HWSURFACE | SDL_DOUBLEBUF );
SDL_WM_SetCaption( WINDOW_TITLE, 0 );
SDL_Event event;
bool gameRunning = true;
while (gameRunning)
{
if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
gameRunning = false;
}
}
}
SDL_Quit();
return 0;
}
- Open up a new Empty Project (.NET). This should give you (surprise!) an empty project with three folders.
- Right-click on the Source Files folder and select Add New Item. Add a .cpp file called main.cpp. Copy-and-paste the above code (or use your own) into main.cpp.
- Choose Tools->Options->Projects->VC++ Directories. Under Show Directories For:, choose Include Files, then click the New Line button. Use the Browse (...) button to find your
/SDL-1.0.8/include folder. Do the same for your library files by choosing Library Files and /SDL-1.0.8/lib. This ensures that VS.NET can find your SDL files. - Choose Project->
Properties->C/C++ ->Code Generation. For Runtime Library, choose Multi-Threaded Debug DLL (/MDd) if you're running in Debug mode, Multi-Threaded DLL if you're running in Release. This ensures that SDL's dynamic libraries are being loaded correctly. - Choose Project->
Properties->Linker->Input. For Additional Dependencies, type in "sdl.lib sdlmain.lib" (w/o the quotes). This actually links the SDL libraries to your project. - Choose Project->
Properties->Linker->System. For SubSystem, choose Console if your program uses int main(), Windows if it uses WinMain. This ensures that the SDL libraries know which program entry point you'll be using (main vs. WinMain). - Copy SDL.dll from your SDL-1.0.8/lib directory into your project directory.
- Build your project. It should compile with perhaps a few warnings, but no errors. Easy, right?
- Properties->Linker->Input->Ignore All Default Libraries is set to Yes
- Properties->C/C++->Code Generation->Runtime Library is set incorrectly
- Properties->Linker->System->SubSystem is not set
- Your main.cpp doesn't contain a main() or WinMain() function.
- Your main function signature isn't written exactly like this: "int main(int argc, char **argv)"
- Properties->C/C++->Code Generation->Runtime Library is set incorrectly
- SDLmain.lib not properly included
- Properties->Linker->Input->Ignore All Default Libraries is set to No.