2

I just want to start in openGL programming, so I installed freeglut3 from the repositories of ubuntu and I have all mesa packages installed, as well as build-essentials.

Later, I copied one simple example of openGL wiki
In first, I tried to compile it with: gcc triangle.c -o triangle.o;
but, later, I read here: Linker error : undefined reference to symbol 'glOrtho' that i have to linked the libraries with -l.
So, I tried with gcc triangle.c -lglut -lGL -Wall -o triangle.o

Both return the same error:

/tmp/ccKLT4ac.o: In function `main':
triangle.c:(.text+0x2b): undefined reference to `glutInit'
triangle.c:(.text+0x37): undefined reference to `glutInitDisplayMode'
triangle.c:(.text+0x4b): undefined reference to `glutInitWindowSize'
triangle.c:(.text+0x57): undefined reference to `glutCreateWindow'
triangle.c:(.text+0x5c): undefined reference to `glewInit'
triangle.c:(.text+0x73): undefined reference to `glewGetErrorString'
triangle.c:(.text+0xaa): undefined reference to `glutDisplayFunc'
triangle.c:(.text+0xaf): undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status

I've tried to include gl.h & glu.h libraries, try with a lot of different example programs in cpp,... and a lot of combinations. All return similar errors.

ah, in /usr/include I have all the libraries:

akronix@ASJ-Netbook:~$ ls /usr/include/GL

freeglut_ext.h  glext.h      glu_mangle.h  glx.h         glxproto.h
freeglut.h      gl.h         glut.h        glxint.h      glxtokens.h
freeglut_std.h  gl_mangle.h  glxew.h       glx_mangle.h  internal
glew.h          glu.h        glxext.h      glxmd.h       wglew.h
Community
  • 1
  • 1
Akronix
  • 1,858
  • 2
  • 19
  • 32
  • You did not mention installing the glew package, nor do your linker directives include `-lGLEW`. Even after you resolve the glut issue, you will have problems with glew until you do this. – Andon M. Coleman Oct 21 '13 at 19:17

1 Answers1

5

Try to compile by placing libraries at the last

gcc triangle.c -Wall -o triangle -lglut -lGL 
digital_revenant
  • 3,274
  • 1
  • 15
  • 24
  • In both cases, the libraries come after the source code, does moving `-Wall` and the `-o` out filename actually fix the problem. Also, shouldn't there be a `-c` argument to compile an object file as per the `*.o` convention? – jozxyqk Oct 22 '13 at 15:19