I am trying to build an opengl project in Visual Studio 2012. I wanted to statically include glew library, so I built it from source and copied the generated glew32sd.lib to my lib directory. I gave this lib path to Visual Studio and put "glew32sd.lib" to my additional dependencies in VS.
Now when I compile a sample code in main.cpp:
#define GLEW_STATIC
#include<GL/glew.h>
int main(){
glewInit();
return 0;
}
I get the following error:
1> main.cpp
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function _glewGetExtension@4
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__wglGetCurrentDC@0 referenced in function _wglewInit@0
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _wglewInit@0
1>C:\Projects\OpenGL\opengl\Debug\opengl.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
In my understanding, this error should be because compiler could not find the definitions for the function call.
Here are a few relevant snapshots: The Library dependencies of my project
Why could this error be coming? I tried rebuilding the solution but that didn't help either. Any suggestion would be helpful.
You have two problems in the linker settings:
You can link against the statically linked version of glew or the dynamically linked one, but never against both. So if you want glew statically linked remove
glew32d.lib
(orglew32.lib
in release mode) from the additional dependencies.Glew requires you to also link agains the opengl library. Add
OpenGL32.lib
to the additional dependencies.