分享

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

 just_person 2011-06-07
The Solution for 'redefinition of exit()' in glut.h and stdlib.h

 

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

D:\Program Files\Microsoft Visual Studio .NET 2003\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 by opening glut.h and find the definition of exit() function (about line 144). Replace them by following. Then rebuild project:


  1. #if defined(_WIN32)  
  2. # ifndef GLUT_BUILDING_LIB  
  3. #if _MSC_VER >= 1200  
  4. _CRTIMP __declspec(noreturnvoid __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行左右),替换为以下内容:

 

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

 

    然后重新编译项目即可。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多