2008-08-18 26 views
28

在我簡單的OpenGL程序中,我獲得有關退出重新定義了以下錯誤:GLUT退出重定義錯誤

1>c:\program files\microsoft visual studio 8\vc\include\stdlib.h(406) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs 
1>  c:\program files\microsoft visual studio 8\vc\platformsdk\include\gl\glut.h(146) : see declaration of 'exit' 

我使用的是內特·羅賓斯GLUT for Win32和得到這個錯誤與Visual Studio 2005或Visual C++ 2005(快遞版)。這個錯誤的原因是什麼,我該如何解決?

回答

68

原因:

stdlib.h中附帶的最近版本的Visual Studio有退出()功能的不同(和相互衝突)的定義。它與glut.h中的定義衝突。

解決方案:

覆蓋的定義glut.h與stdlib.h中。在代碼中將stdlib.h行放在glut.h行的上方。

#include <stdlib.h> 
#include <GL/glut.h> 
15

或本... 要修正這個錯誤,在Solution Explorer選項卡中右鍵單擊項目名稱並選擇屬性 - > C/C++ - >預處理器 - >預處理器定義並追加GLUT_BUILDING_LIB現有定義,用分號隔開。

+0

謝謝!包括你的glut.h上面的stdlib.h沒有爲我工作。這個解決方案沒有 – SunnyD 2013-02-02 20:58:44