2015-11-08 66 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