10

I'm trying to build a very simple OpenGL-app under Ubuntu 10.04 (I have a 32 bit system).

When I'm trying to compile the file, I get the error message:

g++ -L/usr/lib simple.cpp -lglut
/usr/bin/ld: /tmp/ccoPczAo.o: undefined reference to symbol 'glEnd'
/usr/bin/ld: note: 'glEnd' is defined in DSO //usr/lib/libGL.so.1 so try adding it to the linker command line
//usr/lib/libGL.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

Does anybody know what I'm doing wrong?

phimuemue
  • 34,669
  • 9
  • 84
  • 115
  • Not really related to your question, but I see that you are using glEnd(), which is deprecated since GL3. If you are beginning OpenGL programming, I would suggest that you start out using GL3+ with the "core profile". Old OpenGL is not only slow, but also very limited. – glampert Mar 29 '14 at 18:26

2 Answers2

17

You need to include the opengl library on the command line as well as the glut library/. Try adding -lGL to the end of your command line

g++ -L/usr/lib simple.cpp -lglut -lGL
jcoder
  • 29,554
  • 19
  • 87
  • 130
  • Thank you. It solved my problem partially, so I could do the rest (had to add `-lGLU` as well). – phimuemue Aug 13 '10 at 12:48
  • 10
    Anybody can explain why does it print `/usr/lib/libGL.so.1: could not read symbols: Invalid operation`? This looks like it tries to read the missing library, but failing. – misiu_mp Mar 21 '12 at 17:21
1

compile with

g++ main.cpp -o main.bin -lGL -lGLU -lglut

or Try the following make file from OpenGL primer it is very compact. This one helped me to run my Hello world OpenGL. Thanks to OpenGL Primer

CC = g++
SRC = main.cpp imageloader.cpp
LIBS = -lGL -lGLU -lglut
EXEC = cube.bin

all:
       $(CC) $(SRC) -o $(EXEC) $(LIBS)

clean:
       rm -rf $(EXEC) *~
mifthi
  • 151
  • 8