views:

5052

answers:

5

What are the basic steps to compile an OpenGL application using GLUT (OpenGL Utility Toolkit) under Visual C++ Express Edition?

+7  A: 
  1. If you don't have Visual C++ Express Edition (VCEE), download and install VCEE.
  2. The default install of Visual C++ Express Edition builds for the .Net platform. We'll need to build for the Windows platform since OpenGL and GLUT are not yet fully supported under .Net. For this we need the Microsoft Platform SDK. (If you're using an older version of VCEE, download and install the Microsoft Platform SDK. Visual C++ Express Edition will need to be configured to build for Windows platform. All these instructions are available here.)
  3. If you don't have GLUT, download and unzip Nate Robin's Windows port of GLUT.
  4. Add glut.h to your Platform SDK/include/GL/ directory
  5. Link the project with glut.lib. (Go to VCEE Project Properties -> Additional Linker Directories and add the directory which has glut.lib.
  6. Add glut.dll to the Windows/System32 directory, so that all programs using GLUT can find it at runtime.

Your program which uses GLUT or OpenGL should compile under Visual C++ Express Edition now.

Ashwin
+5  A: 

The GLUT port on Nate Robin's site is from 2001 and has some incompatibilities with versions of Visual Studio more recent than that (.NET 2003 and up). The incompatibility manifests itself as errors about redefinition of exit(). If you see this error, there are two possible solutions:

  1. Replace the exit() prototype in glut.h with the one in your stdlib.h so that they match. This is probably the best solution.
  2. An easier solution is to #define GLUT_DISABLE_ATEXIT_HACK before you #include <gl/glut.h> in your program.

(Due credit: I originally saw this advice on the TAMU help desk website.)

I've been using approach #1 myself since .NET 2003 came out, and have used the same modified glut.h with VC++ 2003, VC++ 2005 and VC++ 2008.

Here's the diff for the glut.h I use which does #1 (but in appropriate #ifdef blocks so that it still works with older versions of Visual Studio):

--- c:\naterobbins\glut.h       2000-12-13 00:22:52.000000000 +0900
+++ c:\updated\glut.h    2006-05-23 11:06:10.000000000 +0900
@@ -143,7 +143,12 @@

 #if defined(_WIN32)
 # ifndef GLUT_BUILDING_LIB
-extern _CRTIMP void __cdecl exit(int);
+/* extern _CRTIMP void __cdecl exit(int);  /* Changed for .NET */
+#  if _MSC_VER >= 1200
+extern _CRTIMP __declspec(noreturn) void __cdecl exit(int);
+#  else
+extern _CRTIMP void __cdecl exit(int);
+#  endif
 # endif
 #else
 /* non-Win32 case. */
Baxissimo
Baxissimo: Thanks for pointing this common error and its fix. I've seen that almost every OpenGL newbie faces this error.
Ashwin
A: 

Thanks A lot,Ashwin I had a university project, and I couldn't run the GLUT. You helped me do it.

A: 

yr its nt working at all the errors are 1>------ Build started: Project: huj, Configuration: Release Win32 ------ 1>Compiling... 1>cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release 1>kinematic_demo.cpp 1>main.cpp 1>C:\glut\include\gl/glut.h(149) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs 1> C:\glut\include\gl/glut.h(146) : see declaration of 'exit' 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdlib.h(371) : warning C4985: 'exit': attributes not present on previous declaration. 1> C:\glut\include\gl/glut.h(146) : see declaration of 'exit' 1>app.cpp 1>C:\glut\include\gl/glut.h(149) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs 1> C:\glut\include\gl/glut.h(146) : see declaration of 'exit' 1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdlib.h(371) : warning C4985: 'exit': attributes not present on previous declaration. 1> C:\glut\include\gl/glut.h(146) : see declaration of 'exit' 1>Generating Code... 1>Build log was saved at "file://c:\project2\Release\BuildLog.htm" 1>huj - 2 error(s), 3 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

deep
A: 

not working also when i go in on project properties there is no such thing as "Additional Linker Directories"

Per