2013-05-07 91 views
0

我最近在新计算机上安装了SDL和VS 2010,并且我的测试应用程序出现问题。这里是代码:SDL发生LNK 2019错误

#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; 
} 

,并且错误是:

 
    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)" ([email protected]@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)" ([email protected]@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)" ([email protected]@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)" ([email protected]@YAHXZ) C:\Users\einat\Documents\Visual Studio 2010\Projects\SkeletonOpenGLExample.c\SkeletonOpenGLExample.c\testSDL.obj     SkeletonOpenGLExample 

我已经看过了几个教程,跟着所有的链接指示,但如果没有他们似乎工作。

在此先感谢(抱歉,我无法弄清楚如何让正确格式化

+1

您似乎没有链接到SDL。 – Angew 2013-05-07 07:20:46

+0

您与SDL图书馆_do_链接,不是吗? – 2013-05-07 07:20:47

+0

右键单击项目,然后选择属性>链接器>输入:查看“附加依赖关系”条目,您是否看到列出的SDL .lib文件? – JBL 2013-05-07 07:25:06

回答

2

错误请确保您连接到.lib文件,并确保SDL.dll是在你的SYSTEM32或SYSWOW64(对于x64 pc)文件夹或您正在运行程序的目录。

如果您不确定它们是否已链接,可以使用以下链接在运行时将其链接:还请确保您的项目已设置为控制台

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

您也在使用opengl so als o使用#pragma comment(lib, "opengl32.lib")

可能related

+0

thx的答复,我做了检查,他们被链接,SDL.dll是在SYSTEM32目录和运行该程序的目录,但错误仍然存​​在 – MiloshHasCamo 2013-05-21 10:02:01

+0

我个人喜欢编译库方法,因为它提供即时控制,而无需以IDE依赖的方式寻找项目设置。 – GMasucci 2013-10-28 11:50:00