Reputation: 91
I am trying to get OpenGL to work and have exactly the same problem like here: c++ OpenGL undefined references
I have both packages downloaded and used the same tutorial. Except I use Ubuntu 14.04.2 LTS and my problem is not solved with the mentioned Solution.
It reduces the problem to one undefined reference but still does not work:
g++ -Wall -lGL -o cube main.cpp imageloader.cpp -lglut -lGLU
...
/usr/bin/ld: /tmp/ccWzhHjf.o: undefined reference to symbol 'glTexImage2D'
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from
command line collect2: error: ld returned 1 exit status make: *** [cube] Error 1
How can I fix this problem?
Upvotes: 2
Views: 3060
Reputation: 415
/usr/bin/ld: /tmp/ccWzhHjf.o: undefined reference to symbol 'glTexImage2D'
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing
The part libGL.so.1
basically tells you that there is something wrong with the shared library (it is missing). So all you need to do is to add the GL library like this: -lGL
. The reason it is not working even when you already have -lGL
is that you need to move the library flags after the .cpp
files. So this should work:
g++ -Wall -o cube main.cpp imageloader.cpp -lGL -lglut -lGLU
If you have similiar errors just try to add the flag.
Upvotes: 1
Reputation: 409
Edit the Make File and change it to this
CC = g++
CFLAGS = -Wall -lGL
PROG = cube
SRCS = main.cpp imageloader.cpp
ifeq ($(shell uname),Darwin)
LIBS = -framework OpenGL -framework GLUT
else
LIBS = -lglut -lGLU
endif
all: $(PROG)
$(PROG): $(SRCS)
$(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)
clean:
rm -f $(PROG)
What I did was I added -lGL to CFLAGS and -lGLU to LIBS to the flags so it could link with the required library
Upvotes: 1