When I compile the following two programs one of them compiles and one of themse does not but I don't see a difference. The smaller program is the same only I've taken out a lot of the code so that I'm left with only the minimum that I need to display a window with SDL. I think it would be easier to learn with fewer lines of code and slowly learn the extra and more complicated aspects of using SDL.
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
SDL_Surface* g_pMainSurface = NULL;
SDL_Event g_Event;
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO);
g_pMainSurface = SDL_SetVideoMode(640, 480, 0, SDL_ANYFORMAT);
return 0;
}
In the code above I'm getting this error -> Window.cpp|10|undefined reference to SDL_Init'|
Window.cpp|12|undefined reference to SDL_SetVideoMode'|
The following program compiles fine.
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
SDL_Surface* g_pMainSurface = NULL;
SDL_Event g_Event;
int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf(stderr, "Could not initialize SDL!\n");
exit(1);
}
else
{
fprintf(stdout, "SDL initialized properly!\n");
atexit(SDL_Quit);
}
g_pMainSurface = SDL_SetVideoMode(640, 480, 0, SDL_ANYFORMAT);
if(!g_pMainSurface)
{
fprintf(stderr, "Could not create main surface!\n");
exit(1);
}
for(;;)
{
if(SDL_WaitEvent(&g_Event) == 0)
{
fprintf(stderr, "Error while waiting for an event!\n");
exit(1);
}
// check the type of event
if(g_Event.type == SDL_QUIT)
{
fprintf(stdout, "Quit event has occurred.\n");
break;
}
}
fprintf(stdout, "Terminating program normally.\n");
return 0;
}