Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved external symbol (OpenGL and c++)

Tags:

c++

linker

opengl

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?

like image 591
Cosmo D Avatar asked Sep 12 '25 05:09

Cosmo D


1 Answers

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.

like image 197
Viktor Latypov Avatar answered Sep 14 '25 18:09

Viktor Latypov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!