Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLUT exit redefinition error

Tags:

opengl

glut

In my simple OpenGL program I get the following error about exit redefinition:

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'

I'm using Nate Robins' GLUT for Win32 and get this error with Visual Studio 2005 or Visual C++ 2005 (Express Edition). What is the cause of this error and how do I fix it?

like image 249
Ashwin Nanjappa Avatar asked Aug 18 '08 09:08

Ashwin Nanjappa


2 Answers

Cause:

The stdlib.h which ships with the recent versions of Visual Studio has a different (and conflicting) definition of the exit() function. It clashes with the definition in glut.h.

Solution:

Override the definition in glut.h with that in stdlib.h. Place the stdlib.h line above the glut.h line in your code.

#include <stdlib.h>
#include <GL/glut.h>
like image 147
Ashwin Nanjappa Avatar answered Nov 07 '22 00:11

Ashwin Nanjappa


or this... To fix the error, right click on the project name in the Solution Explorer tab and select Properties -> C/C++ -> Preprocessor -> Preprocessor definitions and append GLUT_BUILDING_LIB to the existing definitions, seperated by semicolons.

like image 25
Alex Avatar answered Nov 07 '22 00:11

Alex