SDL unresolved external symbols

I tried to code a simple file using the SDL but I get the linker errors unresolved external symbols.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Hello world in SDL

#include <SDL.h>

int main(int argc, char* argv[]) {

	// Initialize the SDL and video subsystem
	if (SDL_Init( SDL_INIT_VIDEO ) < 0) {
		return -1;
	}

	// Signal SDL to change main window text to "Hello World"
	SDL_WM_SetCaption("Hello World","Hello World");

	// Create SDL surface to represent game window
	SDL_Surface* screen = SDL_SetVideoMode(640,480,0,0);

	// Load the logo to temporary surface
	SDL_Surface* temp = SDL_LoadBMP("data\\textures\\sdl_logo.bmp");

	// Create working SDL_Surface to match temp display format
	SDL_Surface* bg = SDL_DisplayFormat(temp);


	// Free temp memory allocated to temp SDL_Surface
	SDL_FreeSurface(temp);

	SDL_Event event;
	bool quit = false;
	
	// Main message loop of the game
	while (!quit) {

		// Check message queue for an event
		if (SDL_PollEvent(&event)) {

			// If event was found
			switch (event.type) {

				case SDL_QUIT:	quit = true;
						break;

				case SDL_KEYDOWN:	switch (event.key.keysym.sym) {

							case SDLK_ESCAPE: quit = true;
										break;
							}
							break;
			}
		}


		// Draw background sprite
		SDL_BlitSurface(bg,NULL,screen,NULL);

		// Update current window
		SDL_UpdateRect(screen,0,0,0,0);
	}

	// Free allocated memory for background surface
	SDL_FreeSurface(bg);

	// Quit SDL and allow it to do clean up
	SDL_Quit();
	
	// Return control to windows with no errors
	return 0;
}


It compiles fine, the issue appears when it tries to link. I'm using VC6 on windows, and VC express 2008. Both give the same problem.

I think its something to do with directories or what and I've added the libraries and header files to the directories but I just dont know what to do to get it to work.
http://lazyfoo.net/SDL_tutorials/lesson02/index.php
http://lazyfoo.net/SDL_tutorials/lesson01/index.php

I have started with SDL yesterday, so i dont can help you any further. My guess is that you arent referring to... well, i dont know to what exactly :). I use dev-cpp on windows, and i have to create a project and add "-lmingw32 -lSDLmain -lSDL" to the parameters of the project, as dicribed in the second link.

Hope this helps.
You need to link SDL.lib (that's what the -l option does in gcc).
You'll also need SDL.dll in order to run the exe without it crashing.
Thanks, you guys are great.
Strange, mine works with lib - maybe we did a different download or something.
Yea, I'm not sure where I went wrong but I added the SDL. files to the folders where the .exe was and re-linked the files in directory following the links. It seems to work now; not sure which one the problem was but for now I'm happy with it working.

Think I'll look into Java first though.
Topic archived. No new replies allowed.