PDA

View Full Version : Cmake and opengl - linking error



harnz
25th October 2010, 22:26
Hello,

I am currently writing a qt OpenGL application and I would like to build the project with cmake but unfortunately I am encountering some problems.

My CmakeFiles.txt looks like this:


cmake_minimum_required(VERSION 2.6)

SET(PROJECTNAME plot)

PROJECT(${PROJECTNAME})

set(QT_USE_QTOPENGL TRUE)

# QT4 Handling
FIND_PACKAGE( Qt4 REQUIRED )

INCLUDE(${QT_USE_FILE})

set(qtproject_SRCS
main.cpp
window.cpp
glwidget.cpp
)


SET(foo_MOC_HDRS
glwidget.h
window.h
)

# After this call, foo_MOC_SRCS = moc_glwidget.cxx moc_window.cxx
QT4_WRAP_CPP(foo_MOC_SRCS ${foo_MOC_HDRS})

ADD_EXECUTABLE(${PROJECTNAME} ${qtproject_SRCS} ${foo_MOC_SRCS})

TARGET_LINK_LIBRARIES(${PROJECTNAME} ${QT_LIBRARIES} )


So far there is no problem but as soon as I run make I receive the following errors:



Linking CXX executable plot
Undefined symbols:
"_glEnableClientState", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::initializeGL() in glwidget.cpp.o
GLWidget::initializeGL() in glwidget.cpp.o
"_glDisableClientState", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
"_glGenBuffers", referenced from:
GLWidget::initializeGL() in glwidget.cpp.o
GLWidget::initializeGL() in glwidget.cpp.o
"_glEnable", referenced from:
GLWidget::initializeGL() in glwidget.cpp.o
"_glTranslatef", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
"_glVertexPointer", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::paintGL() in glwidget.cpp.o
"_glBindBuffer", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::initializeGL() in glwidget.cpp.o
"_glBufferData", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::initializeGL() in glwidget.cpp.o
"_glClearColor", referenced from:
GLWidget::initializeGL() in glwidget.cpp.o
"_glColorPointer", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
"_glLoadIdentity", referenced from:
GLWidget::resizeGL(int, int)in glwidget.cpp.o
GLWidget::resizeGL(int, int)in glwidget.cpp.o
GLWidget::paintGL() in glwidget.cpp.o
"_gluPerspective", referenced from:
GLWidget::resizeGL(int, int)in glwidget.cpp.o
"_glClear", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
"_glViewport", referenced from:
GLWidget::resizeGL(int, int)in glwidget.cpp.o
"_glMatrixMode", referenced from:
GLWidget::resizeGL(int, int)in glwidget.cpp.o
GLWidget::resizeGL(int, int)in glwidget.cpp.o
"_glDrawElements", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
"_glRotatef", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
GLWidget::paintGL() in glwidget.cpp.o
"_glDrawArrays", referenced from:
GLWidget::paintGL() in glwidget.cpp.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [plot] Error 1
make[1]: *** [CMakeFiles/plot.dir/all] Error 2
make: *** [all] Error 2


Since all of these errors seem to be connected to my GLWidget (which is a derived class of QGLWidget) I think that cmake is not loading the OpenGL libs.

Do you have any suggestions?

Kind regards,
Harnz

harnz
26th October 2010, 18:00
I found the solution. I have just forgotten to write "FIND_PACKAGE(OpenGL REQUIRED)"

so my CMakeLists.txt looks like this:

#cmake -DQT_QMAKE_EXECUTABLE=/usr/bin/qmake-4.7 CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

SET(PROJECTNAME plot)

PROJECT(${PROJECTNAME})

set(qtproject_SRCS
main.cpp
window.cpp
glwidget.cpp
)


SET(MOC_HEADERS
glwidget.h
window.h
)

# Qt4
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
INCLUDE(${QT_USE_FILE})

QT4_WRAP_CPP(MOC_SOURCES ${MOC_HEADERS})
SET(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES})

# OpenGL
FIND_PACKAGE(OpenGL REQUIRED)
if(NOT OPENGL_FOUND)
message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)

SET(LIBRARIES ${LIBRARIES} ${OPENGL_LIBRARIES})

INCLUDE_DIRECTORIES(${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} )

ADD_EXECUTABLE(${PROJECTNAME} ${qtproject_SRCS} ${MOC_SOURCES})

TARGET_LINK_LIBRARIES(${PROJECTNAME} ${LIBRARIES})


Harnz