Linux development

Started by
5 comments, last by Hollandera 11 years, 6 months ago
I'm trying to set up a development environment on linux but I've run into an error where my ide recognizes the libraries and event goes to finish my line when I type in "glGenTextures," but throws a bunch of errors like these:

/home/william/programming/workspaces/cplusplus/Test2/main.cpp|49|error: undefined reference to 'glGenTextures'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|50|error: undefined reference to 'glBindTexture'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|58|error: undefined reference to 'glTexImage2D'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|63|error: undefined reference to 'glEnable'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|64|error: undefined reference to 'glEnable'|

I set up Opengl using this guy's tutorial(which was very comprehensive, I don't see anywhere I could have missed a step)
http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/video.php

my usr/include/GL contains all the files show in the video.

I've tried compiling this in Code: blocks and with this guy's make file.

I assume its a problem with linking, but I'm having trouble resolve exactly what to do.
Advertisement
Your header files (/usr/include/...) seem to be fine, but you are not linking the library correctly. Can you extract the exact command line that is doing the linking? It might be printed just above the error messages...
You have added the header search path so the preprocessor can find the OpenGL header files.

You also have to add the OpenGL shared libraries for the linker to resolve those symbols. I don't know how to do it in your IDE, but it's gping to be something like "-lGL" added to the linker command line. This will pick up the library [font=courier new,courier,monospace]/usr/lib/libGL.so[/font], which is probably a symbolic link to the real OpenGL library (for example, [font=courier new,courier,monospace]/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0[/font] on my system).

Look around for the linker settings and try adding that.

Stephen M. Webb
Professional Free Software Developer

This is the makefile in question:

[source lang="plain"]CC = g++
CFLAGS = -Wall
PROG = cube

SRCS = main.cpp imageloader.cpp

ifeq ($(shell uname),Darwin)
LIBS = -framework OpenGL -framework GLUT
else
LIBS = -lglut
endif

all: $(PROG)

$(PROG): $(SRCS)
$(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)

clean:
rm -f $(PROG)
[/source]

As you can see, he is not linking to OpenGL but only to GLUT. He must've added them somewhere else, or perhaps he is going through the first branch. Try adding -lGL (note that's a lower-case L, not an i) after -lglut and see what happens.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

The line
LIBS = -lglut
should probably be
LIBS = -lglut -lGLU

Give that a try.

The line
LIBS = -lglut
should probably be
LIBS = -lglut -lGLU

Give that a try.

Linking libGLU will not be sufficient. You have to link -lGL to pick up the OpenGL library.

[font=courier new,courier,monospace]LIBS = -lglut -lGLU -lGL[/font]

Stephen M. Webb
Professional Free Software Developer

Tyvm for the quick replies guys, that was the problem!

This topic is closed to new replies.

Advertisement