Niklas
Niklas

Reputation: 25391

OpenGL Ubuntu 13.10 QtCreator - undefined reference to `glutMainLoop`

If I try to execute the code from here, the OpenGLBook, I get this error messages:

undefined reference to glutMainLoop
undefined reference to glGetString
undefined reference to glClearColor

and so on ... I installed the following packages:

libglew-dev, liblglew1.8, freeglut3-dev and freeglut3.

I am running on Ubuntu 13.10 with Qt Creator v3.0.0.

My .pro file looks like this:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

Build step for debugging is qmake Project.pro -r -spec linux-g++ CONFIG += debug

How can I fix my project?

Upvotes: 1

Views: 1740

Answers (2)

Félix Cantournet
Félix Cantournet

Reputation: 1991

Welcome to c++ ! You are using a library (freeglut I gather) and for this you need 2 things :

1) include the headers (*.h file(s)) that declare the functions/classes/methods that you need

2) your program needs to link with the actual shared library (.so files in Linux)

In your .pro file you need to specify the path to the libraries you want to link with. Add this :

LIBS += -lglut

It means add the library glut to the list of libraries to link.

Upvotes: 0

Niklas
Niklas

Reputation: 25391

Had to change my pro file to

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

# this is the important part
unix|win32: LIBS += -lGLU
unix|win32: LIBS += -lGL
unix|win32: LIBS += -lglut

Upvotes: 3

Related Questions