Search code examples
c++windowsopenglvisual-studio-2015glew

GLEW linking issues cannot find __imp_glGetIntegerv


NOTE: Yes, I have specified GLEW_STATIC.

So I have been through this rodeo before trying to setup glew for use in a new project, but now that I am using glew 2.0 in a project, it is producing linking errors. I've just generated the source in a linux instance and using them like this.

#include "Renderer.h"

#include <windows.h>
#include "GL/glew.h"
#include "Logger.h"

void Renderer::init(void* windowHandle) {
    Logger logger("Renderer::init");

    GLenum result = glewInit();
    if (result != GLEW_OK) {
        LOG(logger) << "Failed to run glew init with error: " << result;
    }
}

This is a function that I have declared in a namespace renderer and define here. The relevance is that I only call glewInit(), that is it.

The linking errors produced are:

Error   LNK2019 unresolved external symbol __imp_glGetIntegerv referenced in function glewContextInit
Error   LNK2019 unresolved external symbol __imp_glGetString referenced in function glewContextInit
Error   LNK2019 unresolved external symbol __imp_wglGetCurrentDC referenced in function wglewInit
Error   LNK2019 unresolved external symbol __imp_wglGetProcAddress referenced in function wglewInit 

The difference here between the normal, "no declared functions are defined" type of errors, these selected four are the only ones missing. Since they have the __imp_ tag attached usually indicating that they are expecting a dynamic library to link in, so something tells me their might be an error in the generated file? Anybody encountered this issue with linking glew?


Solution

  • Of course, after an evening of searching, you find the answer 10 minutes after you post. I had not done this for quite some time so I forgot that win32 still requires you to include the opengl32.lib because it includes the version of glGetIntegerv, (and the other functions) that it should use from the opengl 1.0 implementation that windows includes, instead of querying them from the driver like all the extensions.