C++ – How to use OpenGL and GLUT in Cygwin

ccygwinglutopengl

I've attempted to follow the instructions from various places [1][2][3], but I keep getting link errors when attempting to use GLUT and OpenGL in Cygwin. Everything I try gives me a link error similar to:

$g++ -Wall -pedantic  -c -o triangle.o triangle.cpp
$g++ -o triangle *.o -lglut32 -lglu32 -lopengl32 -o triangle
triangle.o:triangle.cpp:(.text+0x1c): undefined reference to `___glutInitWithExit'
...
triangle.o:triangle.cpp:(.text+0x11c): undefined reference to `_glClear'
...

I have tried C (gcc) and C++ (g++), with and without -mno-cygwin, with various combinations of Cygwin's opengl, libglut-devel, and w32api packages. (I am trying to do this without using X11 if possible.)

Am I doing something wrong here? The instructions on the other stackoverflow links look so simple that I don't know how I could be messing this up.

Thanks in advance.

[1] Starting off with OpenGL under Cygwin
[2] Compiling minimal GLEW application under Cygwin
[3] http://cygwin.com/ml/cygwin/2010-09/msg00238.html

Best Answer

The error indicates that you didn't define _STDCALL_SUPPORTED before including . Also see answers for this question.