Header files are included, but still cannot call the functions..

I'm trying to write a plotting program with c++ under ubuntu12.04. OpenGL is applicated in my code. I have included the necessary header files, but the openGL function still cannot be used.

This is the include codes.
1
2
3
4
5
6
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include <math.h>
#include <cstdlib> 


when I run g++ main.cpp in terminal, terminal displays this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/tmp/ccsiISvK.o: In function `initGL()':
cc.cpp:(.text+0xe): undefined reference to `glMatrixMode'
cc.cpp:(.text+0x13): undefined reference to `glLoadIdentity'
cc.cpp:(.text+0x49): undefined reference to `glOrtho'
cc.cpp:(.text+0x55): undefined reference to `glMatrixMode'
cc.cpp:(.text+0x5a): undefined reference to `glLoadIdentity'
cc.cpp:(.text+0x82): undefined reference to `glClearColor'
cc.cpp:(.text+0x87): undefined reference to `glGetError'
cc.cpp:(.text+0x9b): undefined reference to `gluErrorString'
/tmp/ccsiISvK.o: In function `render()':
cc.cpp:(.text+0x124): undefined reference to `glClear'
cc.cpp:(.text+0x130): undefined reference to `glBegin'
cc.cpp:(.text+0x14f): undefined reference to `glColor3f'
cc.cpp:(.text+0x18b): undefined reference to `glVertex2f'
cc.cpp:(.text+0x1b0): undefined reference to `glEnd'
cc.cpp:(.text+0x1b5): undefined reference to `glutSwapBuffers'
/tmp/ccsiISvK.o: In function `runMainLoop(int)':
cc.cpp:(.text+0x1f7): undefined reference to `glutTimerFunc'
/tmp/ccsiISvK.o: In function `main':
cc.cpp:(.text+0x214): undefined reference to `glutInit'
cc.cpp:(.text+0x228): undefined reference to `glutInitContextVersion'
cc.cpp:(.text+0x234): undefined reference to `glutInitDisplayMode'
cc.cpp:(.text+0x248): undefined reference to `glutInitWindowSize'
cc.cpp:(.text+0x254): undefined reference to `glutCreateWindow'
cc.cpp:(.text+0x27f): undefined reference to `glutDisplayFunc'
cc.cpp:(.text+0x29b): undefined reference to `glutTimerFunc'
cc.cpp:(.text+0x2a0): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status 


Can anyone have a solution for this? I will appreciate that!
Including header files is not enough. You must also link against the library. Googling this would prove instructive.
Topic archived. No new replies allowed.