LNK 2019错误与SDL

时间:2013-05-07 07:18:20

标签: c++ visual-studio-2010 sdl

我最近在新计算机上安装了SDL和VS 2010,我的测试应用程序出现了问题。这是代码:

#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)" (?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

我查了几个教程,并按照所有链接说明进行操作,但是如果它们看起来没有效果则没有。

提前感谢(抱歉,我无法弄清楚如何正确格式化错误

1 个答案:

答案 0 :(得分:2)

确保链接到.lib文件,并确保SDL.dll位于system32或sysWOW64(适用于x64 pc)文件夹或运行该程序的目录中。

如果您不确定它们是否已链接,则可以使用以下命令在运行时链接它。还要确保您的项目设置为控制台。

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

您也在使用opengl,因此也请使用#pragma comment(lib, "opengl32.lib")

可能是related