编译后出现链接器错误

linker error after compiling

本文关键字:错误 链接 编译      更新时间:2023-10-16

我想的链接器有问题

这是我在输出选项卡上得到的:

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:UsersTiagoDesktopProjectsFPSDebugFPS.exe : fatal error LNK1120: 14 unresolved externals

这是链接器的命令行(如果它能帮助你…):

/OUT:"C:UsersTiagoDesktopProjectsFPSDebugFPS.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:"DebugFPS.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:UsersTiagoDesktopProjectsFPSDebugFPS.pdb" /SUBSYSTEM:CONSOLE /PGD:"C:UsersTiagoDesktopProjectsFPSDebugFPS.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE 

更多信息:我已经把OpenGL和SDL文件夹(包含include和lib文件的文件夹)放在我项目的主文件夹中。是它造成了问题吗?

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

你必须做的第一件事:右键单击你的项目,Properties,Linker,Advanced,Entry Point=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;
}

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

相关文章: