cglutundefined-reference

Undefined reference to glutX in C


The following C code:

#include <GL/glu.h>
#include <GL/glut.h>

void Draw() {
}

int main(int C, char *V[]) {
  glutInit(&C, V);
  glutCreateWindow("Basic OpenGL Program");
  glutDisplayFunc(Draw);
  glutMainLoop();
}

...returns:

01.c:(.text+0x25): undefined reference to `glutInit'
/sbin/ld: 01.c:(.text+0x34): undefined reference to `glutCreateWindow'
/sbin/ld: 01.c:(.text+0x43): undefined reference to `glutDisplayFunc'
/sbin/ld: 01.c:(.text+0x48): undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status

I tried to copy them in the same directory, using -lc, using -L with gcc, using clang,ll but still nothing.


Solution

  • Used clang 01.c -lGL -lGLU -lglut -o 01