SDL2 和 SDL_opengl_glext.h 未定义的外部

SDL2 and SDL_opengl_glext.h undefined external

我 运行 在我的 SDL2 项目中尝试摆脱 gl3w 时遇到了问题。我考虑这个的原因仅仅是因为我注意到我的 gl3w 版本不包含 "glAlphaFunc" 但 SDL_opengl_glext.h 包含。

看来我需要定义以下内容:

#define GL_GLEXT_PROTOTYPES
#define GLX_GLEXT_PROTOTYPES

所以在我注意到 SDL_opengl_glext.h 存在之后,我想也许我可以简单地包括 SDL_opengl.h 和 SDL_opengl_glext.h(就像我在 iOS 上所做的那样:SDL_opengl.h 和SDL_opengles.h), 但现在我遇到了未定义外部的问题。

我目前引用的lib文件:

opengl32.lib;glu32.lib;SDL2.lib;SDL2main.lib;SDL2test.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;libboost_filesystem-vc140-mt-1_58.lib;libboost_system-vc140-mt-1_58.lib;libpq.lib;ssleay32.lib;libeay32.lib;%(AdditionalDependencies)

我的问题是:使用 SDL2 我可以 link 任何其他 lib 文件来解决这个问题,我该如何正确使用 SDL_opengl_glext.h?我没有看到任何关于这个问题的明确文件。

错误涌现:

1>emitter.obj : error LNK2019: unresolved external symbol __imp_glBindBuffer referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glBindBuffer
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glBindBuffer
1>emitter.obj : error LNK2019: unresolved external symbol __imp_glGenBuffers referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glGenBuffers
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glGenBuffers
1>emitter.obj : error LNK2019: unresolved external symbol __imp_glBufferData referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glBufferData
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glBufferData
1>emitter.obj : error LNK2019: unresolved external symbol __imp_glDisableVertexAttribArray referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glDisableVertexAttribArray
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glDisableVertexAttribArray
1>emitter.obj : error LNK2019: unresolved external symbol __imp_glEnableVertexAttribArray referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glEnableVertexAttribArray
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glEnableVertexAttribArray
1>emitter.obj : error LNK2019: unresolved external symbol __imp_glUseProgram referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glUseProgram
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glUseProgram
1>emitter.obj : error LNK2019: unresolved external symbol __imp_glVertexAttribPointer referenced in function "protected: virtual void __cdecl MV::Scene::Emitter::defaultDrawImplementation(void)" (?defaultDrawImplementation@Emitter@Scene@MV@@MEAAXXZ)
1>drawable.obj : error LNK2001: unresolved external symbol __imp_glVertexAttribPointer
1>spineMV.obj : error LNK2001: unresolved external symbol __imp_glVertexAttribPointer
1>render.obj : error LNK2019: unresolved external symbol __imp_glActiveTexture referenced in function "public: void __cdecl MV::Shader::set(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::shared_ptr<class MV::TextureDefinition> const &,unsigned int)" (?set@Shader@MV@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$shared_ptr@VTextureDefinition@MV@@@4@I@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glBlendFuncSeparate referenced in function "public: void __cdecl MV::Draw2D::defaultBlendFunction(void)" (?defaultBlendFunction@Draw2D@MV@@QEAAXXZ)
1>render.obj : error LNK2019: unresolved external symbol __imp_glBlendEquationSeparate referenced in function "public: void __cdecl MV::glExtensionBlendMode::setBlendEquation(unsigned int,unsigned int)" (?setBlendEquation@glExtensionBlendMode@MV@@QEAAXII@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glAttachShader referenced in function "public: class MV::Shader * __cdecl MV::Draw2D::loadShaderCode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?loadShaderCode@Draw2D@MV@@QEAAPEAVShader@2@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glCompileShader referenced in function "private: void __cdecl MV::Draw2D::loadPartOfShader(unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?loadPartOfShader@Draw2D@MV@@AEAAXIAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glCreateProgram referenced in function "public: class MV::Shader * __cdecl MV::Draw2D::loadShaderCode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?loadShaderCode@Draw2D@MV@@QEAAPEAVShader@2@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glCreateShader referenced in function "public: class MV::Shader * __cdecl MV::Draw2D::loadShaderCode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?loadShaderCode@Draw2D@MV@@QEAAPEAVShader@2@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGetActiveUniform referenced in function "public: __cdecl MV::Shader::Shader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,bool)" (??0Shader@MV@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@I_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGetProgramiv referenced in function "public: __cdecl MV::Shader::Shader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,bool)" (??0Shader@MV@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@I_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGetShaderiv referenced in function "private: void __cdecl MV::Draw2D::validateShaderStatus(unsigned int,bool)" (?validateShaderStatus@Draw2D@MV@@AEAAXI_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGetShaderInfoLog referenced in function "private: void __cdecl MV::Draw2D::validateShaderStatus(unsigned int,bool)" (?validateShaderStatus@Draw2D@MV@@AEAAXI_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGetUniformLocation referenced in function "public: __cdecl MV::Shader::Shader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,bool)" (??0Shader@MV@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@I_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glIsProgram referenced in function "public: __cdecl MV::Shader::Shader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,bool)" (??0Shader@MV@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@I_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glLinkProgram referenced in function "public: class MV::Shader * __cdecl MV::Draw2D::loadShaderCode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?loadShaderCode@Draw2D@MV@@QEAAPEAVShader@2@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glShaderSource referenced in function "private: void __cdecl MV::Draw2D::loadPartOfShader(unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?loadPartOfShader@Draw2D@MV@@AEAAXIAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glUniform1i referenced in function "public: void __cdecl MV::Shader::set(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::shared_ptr<class MV::TextureDefinition> const &,unsigned int)" (?set@Shader@MV@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$shared_ptr@VTextureDefinition@MV@@@4@I@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glUniform1fv referenced in function "public: void __cdecl MV::Shader::set(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,float)" (?set@Shader@MV@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@M@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glUniformMatrix4fv referenced in function "public: void __cdecl MV::Shader::set(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class MV::TransformMatrix const &)" (?set@Shader@MV@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVTransformMatrix@2@@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glBindRenderbuffer referenced in function "public: void __cdecl MV::glExtensionFramebufferObject::startUsingFramebuffer(class std::weak_ptr<class MV::Framebuffer>,bool)" (?startUsingFramebuffer@glExtensionFramebufferObject@MV@@QEAAXV?$weak_ptr@VFramebuffer@MV@@@std@@_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glDeleteRenderbuffers referenced in function "public: __cdecl MV::Framebuffer::~Framebuffer(void)" (??1Framebuffer@MV@@QEAA@XZ)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGenRenderbuffers referenced in function "public: class std::shared_ptr<class MV::Framebuffer> __cdecl MV::glExtensionFramebufferObject::makeFramebuffer(class MV::Point<int> const &,class MV::Size<int> const &,unsigned int,class MV::Color const &)" (?makeFramebuffer@glExtensionFramebufferObject@MV@@QEAA?AV?$shared_ptr@VFramebuffer@MV@@@std@@AEBV?$Point@H@2@AEBV?$Size@H@2@IAEBVColor@2@@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glRenderbufferStorage referenced in function "public: void __cdecl MV::glExtensionFramebufferObject::startUsingFramebuffer(class std::weak_ptr<class MV::Framebuffer>,bool)" (?startUsingFramebuffer@glExtensionFramebufferObject@MV@@QEAAXV?$weak_ptr@VFramebuffer@MV@@@std@@_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glBindFramebuffer referenced in function "public: void __cdecl MV::glExtensionFramebufferObject::startUsingFramebuffer(class std::weak_ptr<class MV::Framebuffer>,bool)" (?startUsingFramebuffer@glExtensionFramebufferObject@MV@@QEAAXV?$weak_ptr@VFramebuffer@MV@@@std@@_N@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glDeleteFramebuffers referenced in function "public: __cdecl MV::Framebuffer::~Framebuffer(void)" (??1Framebuffer@MV@@QEAA@XZ)
1>render.obj : error LNK2019: unresolved external symbol __imp_glGenFramebuffers referenced in function "public: class std::shared_ptr<class MV::Framebuffer> __cdecl MV::glExtensionFramebufferObject::makeFramebuffer(class MV::Point<int> const &,class MV::Size<int> const &,unsigned int,class MV::Color const &)" (?makeFramebuffer@glExtensionFramebufferObject@MV@@QEAA?AV?$shared_ptr@VFramebuffer@MV@@@std@@AEBV?$Point@H@2@AEBV?$Size@H@2@IAEBVColor@2@@Z)
1>render.obj : error LNK2019: unresolved external symbol __imp_glFramebufferTexture2D referenced in function "public: void __cdecl MV::glExtensionFramebufferObject::startUsingFramebuffer(class std::weak_ptr<class MV::Framebuffer>,bool)" (?startUsingFramebuffer@glExtensionFramebufferObject@MV@@QEAAXV?$weak_ptr@VFramebuffer@MV@@@std@@_N@Z)
1>C:\git\MoonDog\x64\Release\M2tMLibrary.exe : fatal error LNK1120: 33 unresolved externals

What is an undefined reference / unresolved external symbol error and how do I fix it?

您需要 link 到 SDL2main.lib 然后到SDL2.lib 然后是任何其他 SDL 库。

确保您link正在使用您的编译器适合的二进制文件,并且具有正确的体系结构。

如果都失败了,自己编译SDL。

这不是您使用 OpenGL 扩展的方式。您需要在 运行 时间使用 SDL_GL_GetProcAddress 加载扩展函数或使用任何现有的 opengl loaders.

如果您只需要这一个功能,您可以自己定义它的原型或在运行时加载它。请注意,较新的 GL 版本已弃用 AlphaFunc(这就是 gl3w 没有它的原因 - 因为它针对 GL 3 或更高版本),因此如果您针对这些版本,则无法使用它。