Jul 15, 2009

cygwin undefined reference to `_glEnd' and related OpenGL function

Sometime, when building OpenGL application under cygwin, we fail to compile with following message or relating OpenGL function message "undefined reference to `_glEnd' and related OpenGL function"

The simple test is such as following
#include <GL/gl.h>
int main() { glEnd(); return 0; }

$ gcc -lGL test.c -o test
/.../.../ccO7Cfcr.o:test.c:(.text+0x2b): undefined reference to `_glEnd'
collect2: ld returned 1 exit status

That is because the OpenGL library on cygwin is depended on GLU library also. We need to link with GLU when linking with GL
Change the link command to $ gcc -lGL -lGLU test.c -o test and everything is OK.

I met this issue while compiling ShivaVG package on cygwin

No comments: