C++ – Unresolved external symbol (OpenGL and c++)

clinkeropengl

OK, so I'm writing a little project, nothing complex, it just has several classes.
As the title implies, it uses OpenGL. At the moment, there's no "real" main function.
I have included glew.h wherever I've used gl* function calls, and added to the linker input glew32.lib.

And yet, it gives me this:

Error 2 error LNK2019: unresolved external symbol
_imp_glBindTexture@8 referenced in function "public: void __thiscall Texture2D::Bind(unsigned int)"
(?Bind@Texture2D@@QAEXI@Z) Texture.obj Licenta

… and a host of other unresolved external symbol errors regarding OpenGL texture functions. But it doesn't complain about this:

glBindVertexArray(m_VAO);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size(), &Indices[0], GL_STATIC_DRAW);

or this:

glDrawElementsBaseVertex(GL_TRIANGLES, 
                             m_Entries[i].NumIndices, 
                             GL_UNSIGNED_INT, 
                             (void*)(sizeof(unsigned int) * m_Entries[i].BaseIndex), 
                             m_Entries[i].BaseVertex);

So, what's the deal? If one gl* function call failed linking, wouldn't ALL have to fail?

Best Answer

glBindTexture is a "core" OpenGL feature. This function resides in opengl32.dll, so just add the opengl32.lib to your linker input.

glDrawElementsBaseVertex and glBindVertexArray are extensions and GLEW defines these as function pointers (with dynamic late binding done in runtime), thus no "unresolved symbol" errors.

Related Topic