编译后链接器错误

时间:2012-03-11 21:23:33

标签: c++ c opengl sdl

我猜测链接器有问题

这是我在输出标签上得到的结果:

1>main-light.obj : error LNK2019: unresolved external symbol _SDL_FreeSurface referenced in function "private: unsigned int __thiscall objloader::loadTexture(char const *)" (?loadTexture@objloader@@AAEIPBD@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_LoadBMP_RW referenced in function "private: unsigned int __thiscall objloader::loadTexture(char const *)" (?loadTexture@objloader@@AAEIPBD@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_RWFromFile referenced in function "private: unsigned int __thiscall objloader::loadTexture(char const *)" (?loadTexture@objloader@@AAEIPBD@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_GetTicks referenced in function "public: void __thiscall Player::init(void)" (?init@Player@@QAEXXZ)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_GetKeyState referenced in function "void __cdecl Control(float,float,bool)" (?Control@@YAXMM_N@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_WarpMouse referenced in function "void __cdecl Control(float,float,bool)" (?Control@@YAXMM_N@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_GetMouseState referenced in function "void __cdecl Control(float,float,bool)" (?Control@@YAXMM_N@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_ShowCursor referenced in function "void __cdecl Control(float,float,bool)" (?Control@@YAXMM_N@Z)
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_Delay referenced in function _SDL_main
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_GL_SwapBuffers referenced in function _SDL_main
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_PollEvent referenced in function _SDL_main
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_SetVideoMode referenced in function _SDL_main
1>main-light.obj : error LNK2019: unresolved external symbol _SDL_Init referenced in function _SDL_main
1>MSVCRT.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Tiago\Desktop\Projects\FPS\Debug\FPS.exe : fatal error LNK1120: 14 unresolved externals

这是链接器的命令行(如果它可以帮助你......):

/OUT:"C:\Users\Tiago\Desktop\Projects\FPS\Debug\FPS.exe" /NOLOGO "SDL.lib" "SDLmain.lib" "glu32.lib" "glut32.lib" "opengl32.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\FPS.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\Tiago\Desktop\Projects\FPS\Debug\FPS.pdb" /SUBSYSTEM:CONSOLE /PGD:"C:\Users\Tiago\Desktop\Projects\FPS\Debug\FPS.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE 

更多信息: 我把OpenGL和SDL文件夹(包含include文件和lib文件的文件夹)放在我项目的主文件夹中。它导致了这个问题吗?

1 个答案:

答案 0 :(得分:1)

我在SDL文档中找不到任何与正确配置项目有关的内容。头文件提供了一些提示,它使用非标准的#defines来选择平台。这解释了第一组链接器错误,必须正确设置DECLSPEC宏。对于一些真的神秘的原因,它也想重命名main(),这是你上次链接器错误的原因。不知道为什么这是必要的,这些黑客往往被用作过滤器。如同,“不能自己解决这个问题,不要用你的其他问题来解决问题”。

您必须做的第一件事:右键单击您的项目,属性,链接器,高级,入口点= SDL_main。使您的代码看起来与此类似,我对路径进行了硬编码并告诉链接器要链接的内容:

include "stdafx.h"
#define __WIN32__    // Non-standard define to select the platform
#include "c:/temp/sdl-1.2.15/include/sdl.h"
#pragma comment(lib, "c:/temp/sdl-1.2.15/lib/x86/sdl.lib")


int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);   // Just an example
    // etc...
    return 0;
}

它正确链接,这就是我尝试过的。运行它需要sdl.dll与.exe在同一目录中。祝你好运,听起来你需要它。