2015-11-08 110 views
1

我想在Visual Studio 2012中建立一个opengl项目。我想静态地包括glew库,所以我从源代码构建它,并将生成的glew32sd.lib复制到我的lib目录。我把这个lib路径给了Visual Studio,并把“glew32sd.lib”添加到我在VS中的其他依赖项中。链接器错误,当库静态链接时glew

现在,当我编译示例代码在main.cpp中:

#define GLEW_STATIC 
#include<GL/glew.h> 
int main(){ 
    glewInit(); 
    return 0; 
} 

我得到以下错误:

1> main.cpp 
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] 
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] 
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] 
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 ========== 

在我的理解,这个错误应该是因为编译器找不到函数调用的定义。

这里有一些相关的快照: The Library dependencies of my project

Path to libs

为什么会这样的错误来吗?我尝试重建解决方案,但这也没有帮助。任何建议都会有所帮助。

回答

3

你必须在链接器设置两个问题:

  • 您可以针对GLEW的静态链接的版本进行链接或动态链接的一个,但从未对阵双方。因此,如果您想要将静态链接从其他依赖关系中删除glew32d.lib(或在发布模式下为glew32.lib)。

  • Glew要求你再次链接opengl库。将OpenGL32.lib添加到其他依赖项。

+0

它解决了这个问题!谢谢您的帮助。 – ashutosh