0
votes

i recently installed SDL and VS 2010 on a new computer and im having issues with my test application. here is the code:

#include <SDL.h>
#include <SDL_opengl.h>
#undef main

int INIT_SDL_OPENGL()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
    return 1;
}

SDL_SetVideoMode(640, 360, 32, SDL_OPENGL);

SDL_WM_SetCaption("Skeleton Example", NULL);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);

return 0;
}

void EndQuitly()
{
SDL_Quit();
exit(0);
 }

int main(int argc, char **argv)
{
INIT_SDL_OPENGL();

glBegin(GL_LINES);
   glVertex2f(360, 180);
   glVertex2f(640, 360);
glEnd();

EndQuitly();

return 0;
}   

and the errors are:

    error LNK1120: 4 unresolved externals   C:\Users\einat\Documents\Visual Studio 2010\Projects\SkeletonOpenGLExample.c\Debug\SkeletonOpenGLExample.exe    1   SkeletonOpenGLExample
error LNK2019: unresolved external symbol _SDL_Init referenced in function "int __cdecl INIT_SDL_OPENGL(void)" (?INIT_SDL_OPENGL@@YAHXZ)    C:\Users\einat\Documents\Visual Studio 2010\Projects\SkeletonOpenGLExample.c\SkeletonOpenGLExample.c\testSDL.obj    SkeletonOpenGLExample
      error LNK2019: unresolved external symbol _SDL_Quit referenced in function "void __cdecl EndQuitly(void)" (?EndQuitly@@YAXXZ) C:\Users\einat\Documents\Visual Studio 2010\Projects\SkeletonOpenGLExample.c\SkeletonOpenGLExample.c\testSDL.obj    SkeletonOpenGLExample
    error LNK2019: unresolved external symbol _SDL_SetVideoMode referenced in  function "int __cdecl INIT_SDL_OPENGL(void)" (?INIT_SDL_OPENGL@@YAHXZ)    C:\Users\einat\Documents\Visual Studio 2010\Projects\SkeletonOpenGLExample.c\SkeletonOpenGLExample.c\testSDL.obj     SkeletonOpenGLExample
    error LNK2019: unresolved external symbol _SDL_WM_SetCaption referenced in   function     "int __cdecl INIT_SDL_OPENGL(void)" (?INIT_SDL_OPENGL@@YAHXZ)    C:\Users\einat\Documents\Visual Studio 2010\Projects\SkeletonOpenGLExample.c\SkeletonOpenGLExample.c\testSDL.obj                 SkeletonOpenGLExample

i have looked up several tutorials and followed all the linking instructions but none if them seem to work.

thanks in advance (sorry i couldn't figure out how to get the errors properly formatted

1
It seems you're not linking to SDL.Angew is no longer proud of SO
You do link with the SDL library, don't you?Some programmer dude
When you right click your project, then Properties > Linker > Input : look at the "Additionnal Dependencies" entry, do you see the SDL .lib files listed ?JBL

1 Answers

2
votes

Make sure you are linking to the .lib files and make sure the SDL.dll is in your system32 or sysWOW64(for x64 pc) folder or the directory you are running the program from.

If you are not sure they are linked, you can use the following to link it at runtime. Also make sure your project is set to console.

#pragma comment(lib, "SDLmain.lib")
#pragma comment(lib, "SDL.lib")

You are also using opengl so also use #pragma comment(lib, "opengl32.lib")

Possibly related.