1

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
M2tM
  • 4,415
  • 1
  • 34
  • 43

2 Answers2

1

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.

keltar
  • 17,711
  • 2
  • 37
  • 42
  • Yeah, I'm aware of that as well, and I was using gl3w as an opengl loader. It appeared as if SDL2 included an opengl loader, (that's what I thought SDL_opengl_glext.h might be.) I figured I might have been missing a function call similar to gl3wInit(); but wasn't sure. Do you know what SDL_opengl_glext.h is supposed to be for if not opengl loading? Thanks for the heads up on AlphaFunc, so I should just include that in my shaders then! I may just stick with gl3w if SDL2 doesn't have an opengl loader, I'd like to give you a chance to read this comment, but so far I may accept your answer – M2tM Jun 27 '16 at 17:08
  • 1
    `SDL_opengl.h` and `SDL_opengl_glext.h` are just portable replacements for `gl.h` and `glext.h`. `glext.h` itself is rarely used, even more so with `GL_GLEXT_PROTOTYPES` define active (without it it provides type definitions for function pointers - may be useful if you write your own extension loader). I'm pretty sure you can use gl3w with SDL as the solve very different things (SDL+glew is very common too). All that SDL provides in terms of GL function loading is portable `SDL_GL_GetProcAddress`, but then again you only care about it if you write extension loader. – keltar Jun 27 '16 at 17:22
  • Thanks a bunch, this clears some confusion. I used to load my own extensions, and a few years ago moved to gl3w to just do it for me, and hadn't thought of it again until AlphaFunc came up in an example with stencil buffers and I looked into how to load that function (which I don't need as it's deprecated anyway and I can do it in my shaders). Thanks a ton! – M2tM Jun 27 '16 at 17:24
0

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

You need to link to SDL2main.lib Then to SDL2.lib Then any other SDL libraries.

Make sure you're linking to a binary that's fine by your compiler, and of the right architecture.

If all else fails, compile SDL yourself.

Community
  • 1
  • 1
Ivan Rubinson
  • 3,001
  • 4
  • 19
  • 48