简体   繁体   English

编译后链接器错误

[英]linker error after compiling

Im having a problem with the linker i guess 我猜链接器有问题

This is what i get on the output tab: 这是我在输出选项卡上得到的:

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

here is the command line of the linker (if it can help you...): 这是链接器的命令行(如果它可以帮助您...):

/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 

More information: i've put the OpenGL and SDL folder (the folder with the include and lib files) in the main folder of my project. 更多信息:我已经将OpenGL和SDL文件夹(包含include和lib文件的文件夹)放在项目的主文件夹中。 Is it causing the problem? 是引起问题吗?

I cannot find anything relevant in the SDL docs on how to configure your project properly. 在SDL文档中找不到有关如何正确配置项目的任何相关信息。 The header files gives some hints, it uses non-standard #defines to select the platform. 头文件提供了一些提示,它使用非标准的#defines选择平台。 Which explains the first set of linker errors, the DECLSPEC macro has to be set correctly. 解释了第一组链接器错误,必须正确设置DECLSPEC宏。 For some really mysterious reason it wants to rename main() as well, the reason for your last linker error. 由于某些真正神秘的原因,它也想重命名main(),这是最后一个链接器错误的原因。 No clue why any of this is necessary, these kind of hacks tend to be used as a filter. 不清楚为什么需要这些,这些黑客通常被用作过滤器。 As in, "can't figure this out by yourself, don't bug us with your other questions". 例如,“不能自己解决这个问题,不要让我们遇到其他问题”。

First thing you have to do: right-click your project, Properties, Linker, Advanced, Entry Point = SDL_main. 您要做的第一件事:右键单击项目,属性,链接器,高级,入口点= SDL_main。 Make your code look similar to this, I hard-coded the paths and told the linker what to link: 使您的代码看起来与此类似,我对路径进行了硬编码,并告诉链接器要链接的内容:

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

It linked correctly, that's all I tried. 它链接正确,这就是我尝试的全部。 Running it requires sdl.dll in the same directory as your .exe. 要运行它,需要将sdl.dll与.exe放在同一目录中。 Good luck with it, sounds like you'll need it. 祝您好运,听起来您需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM