Search code examples
c++opengllinker-errorssdl-2unresolved-external

SDL2 and SDL_opengl_glext.h undefined external


I'm running across problems when trying to move away from gl3w in my SDL2 project. The reason I'm considering this is simply because I noticed my version of gl3w doesn't include "glAlphaFunc" but SDL_opengl_glext.h does.

It seems I need to define the following:

#define GL_GLEXT_PROTOTYPES
#define GLX_GLEXT_PROTOTYPES

So after I noticed SDL_opengl_glext.h exists I figured maybe I could simply include SDL_opengl.h and SDL_opengl_glext.h (as I do on iOS: SDL_opengl.h and SDL_opengles.h), but now I'm getting issues with undefined externals.

The lib files I'm currently referencing:

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)

My question is: With SDL2 can I link any other lib files to fix this issue, how do I correctly use SDL_opengl_glext.h? I don't see any clear documentation on this issue in particular.

Error Spew:

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

Solution

  • This is not how you use OpenGL extensions. You need to load extension functions at run time with SDL_GL_GetProcAddress or use any of existing opengl loaders.

    If you only need this one function you can define its prototype yourself or load it at runtime. Note that newer GL vesions deprecated AlphaFunc (which is the reason why gl3w don't have it - as it targets GL 3 or higher), so you cannot use it if you target these versions.