遮天 有声:Windows下stdlib.h与glut.h中exit()函数重复定义的解决方案

来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 00:17:31
The Solution for 'redefinition of exit()'in glut.h and stdlib.h

 

    When develop GLUT projects in Windows system, wealways encounter this problem or like:

D:\Program Files\Microsoft VisualStudio .NET2003\Vc7\include\stdlib.h(256) : error C2381: 'exit' :redefinition;__declspec(noreturn) differs
D:\programs\glut-3.7.6-bin\GL\glut.h(146) : see declaration of'
exit'

    We could simply solve this problem byopening glut.h and find the definition of exit() function (about line144). Replace them by following. Then rebuild project:


view plaincopy to clipboardprint?
  1. #if defined(_WIN32)  
  2. # ifndef GLUT_BUILDING_LIB  
  3. #if _MSC_VER >= 1200  
  4. _CRTIMP __declspec(noreturn) void __cdecl exit(int);  
  5. #else  
  6. _CRTIMP void __cdecl exit(int);  
  7. #endif  
  8. # endif  
  9. #else  

 

   Windows下用到GLUT进行OpenGL开发时,时常会碰到exit()这个函数在stdlib.h与glut.h两个头文件中重复定义的情况,解决方案如下:

    打开glut.h,找到exit()函数定义的地方(144行左右),替换为以下内容:

 

view plaincopy to clipboardprint?
  1. #if defined(_WIN32)  
  2. # ifndef GLUT_BUILDING_LIB  
  3. #if _MSC_VER >= 1200  
  4. _CRTIMP __declspec(noreturn) void __cdecl exit(int);  
  5. #else  
  6. _CRTIMP void __cdecl exit(int);  
  7. #endif  
  8. # endif  
  9. #else  

 

    然后重新编译项目即可。