1

I'm using Fedora 16. I've installed freeglut and freeglut-devel packages. I tried to rum a simple opengl program, but i'm getting the following error

gcc cube.c -o cube -lglut
/usr/bin/ld: /tmp/ccSFol4w.o: undefined reference to symbol 'gluLookAt'
/usr/bin/ld: note: 'gluLookAt' is defined in DSO /usr/lib/libGLU.so.1 so try adding it to the linker command line
/usr/lib/libGLU.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
genpfault
  • 51,148
  • 11
  • 85
  • 139
Rudra Murthy
  • 710
  • 2
  • 8
  • 20
  • 3
    why someone is always so mean by downing a question that he is either not interested or unable to answer? This question help me solve a similar question. This question and the asker should be respected. – user2384994 May 10 '14 at 12:10

5 Answers5

7

Compile : g++ sampleCode.cpp -lglut -lGL -lGLU

run : ./a.out

is your answer.

Sabri Meviş
  • 2,231
  • 1
  • 32
  • 38
4

You have to link some gl libraries.

g++ cube.c -o cube -I /usr/lib/libglut.so.3 /usr/lib/libGL.so.1 /usr/lib/libGLU.so.1 -lGL
demonplus
  • 5,613
  • 12
  • 49
  • 68
2

I think you should consult some introduction text on compilers, linkers and libraries, i.e. how the pieces come together when building a program. In essence the linker is telling you, that there are some loose ends and it cannot finish linking the program due to them. Adding a library happens by the -l switch with library name (GLU in your case), not by giving it a full path to the library file.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
1

I got the exact same problem in Ubuntu 12.04 LTS when I wrote:

g++ square.cpp -lglut

But then I found on the web that some people also added -lGL and lGLU so I did it and it compiles now:

g++ square.cpp -lglut -lGL -GLU
demonplus
  • 5,613
  • 12
  • 49
  • 68
zelgit
  • 131
  • 1
  • 5
  • What does the `gut` library do? – genpfault Feb 19 '13 at 20:47
  • 1
    Sorry it should of course be -lglut instead of -lgut. It is a OpenGL library that is needed, you could read more here: http://en.wikipedia.org/wiki/OpenGL_Utility_Toolkit – zelgit Feb 28 '14 at 01:50
1

do what it says

gcc cube.c -o cube -lglut -lGLU
stativ
  • 1,452
  • 12
  • 23