You are not logged in.

1

Friday, July 6th 2012, 10:56pm

opengl with cmake

Hi, I have a problem trying to compile a small application that uses QtOpenGL with CMake. Here are the CMake files:

Source code

1
2
3
4
5
6
7
project(tracking-example)
cmake_minimum_required(VERSION 2.8)
find_package(Qt4 REQUIRED)
find_package(OpenCV REQUIRED)
add_definitions(${QT_DEFINITIONS})
include_directories(${QT_INCLUDES})
add_subdirectory(src)


and:

Source code

1
2
3
4
5
6
7
8
9
10
set(tracking-example_SRCS
	main.cpp
	MainWindow.cpp
	glwidget.cpp
)
set(QT_USE_QTOPENGL TRUE)
INCLUDE (${QT_USE_FILE})
qt4_wrap_cpp(tracking-example_SRCS MainWindow.h)
add_executable(tracking-example ${tracking-example_SRCS})
target_link_libraries(tracking-example ${OpenCV_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_LIBRARIES})


This is the command make generates and its output (the relevant part):

Source code

1
2
3
4
5
6
cd /home/dyeray/pfc/tracking-example/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/tracking-example.dir/link.txt --verbose=1
/usr/bin/c++   	CMakeFiles/tracking-example.dir/main.cpp.o CMakeFiles/tracking-example.dir/MainWindow.cpp.o CMakeFiles/tracking-example.dir/glwidget.cpp.o CMakeFiles/tracking-example.dir/moc_MainWindow.cxx.o  -o tracking-example -rdynamic -L/usr/lib64/lib64 -lopencv_gpu -lopencv_contrib -lopencv_legacy -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lQtCore -lQtGui -lQtOpenGL -lQtGui -lQtCore -lQtOpenGL -Wl,-rpath,/usr/lib64/lib64 
/usr/bin/ld: CMakeFiles/tracking-example.dir/glwidget.cpp.o: undefined reference to symbol 'glMatrixMode'
/usr/bin/ld: note: 'glMatrixMode' is defined in DSO /lib64/libGL.so.1 so try adding it to the linker command line
/lib64/libGL.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status


As you see, linking to qtopengl is not enough to detect the opengl functions like glMatrixMode. If I add to target_link_libraries GL GLU then the output is:

Source code

1
2
3
4
5
6
7
8
/usr/bin/c++   	CMakeFiles/tracking-example.dir/main.cpp.o CMakeFiles/tracking-example.dir/MainWindow.cpp.o CMakeFiles/tracking-example.dir/glwidget.cpp.o CMakeFiles/tracking-example.dir/moc_MainWindow.cxx.o  -o tracking-example -rdynamic -L/usr/lib64/lib64 -lopencv_gpu -lopencv_contrib -lopencv_legacy -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lQtCore -lQtGui -lQtOpenGL -lQtGui -lQtCore -lGL -lGLU -lQtOpenGL -lGL -lGLU -Wl,-rpath,/usr/lib64/lib64 
CMakeFiles/tracking-example.dir/main.cpp.o: In function `GLWidget::~GLWidget()':
main.cpp:(.text._ZN8GLWidgetD2Ev[_ZN8GLWidgetD5Ev]+0x13): undefined reference to `vtable for GLWidget'
main.cpp:(.text._ZN8GLWidgetD2Ev[_ZN8GLWidgetD5Ev]+0x1f): undefined reference to `vtable for GLWidget'
CMakeFiles/tracking-example.dir/glwidget.cpp.o: In function `GLWidget::GLWidget(QWidget*)':
glwidget.cpp:(.text+0x45): undefined reference to `vtable for GLWidget'
glwidget.cpp:(.text+0x51): undefined reference to `vtable for GLWidget'
collect2: error: ld returned 1 exit status


I don't know if GL GLU makes the error earlier (if it hides qtopengl to the linker) or if I have to link to this and this is other error more forward in the linking.

2

Saturday, July 7th 2012, 2:22pm

this is a programming forum, not a build forum.

maybe this help, otherwise...
http://www.qtcentre.org/threads/31393-SO…-A-moc-handling)
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Saturday, July 7th 2012, 2:44pm

you ca use:

QT+=coregui+ opengl

in qt file proj.

4

Saturday, July 7th 2012, 5:01pm

this is a programming forum, not a build forum.

maybe this help, otherwise...
http://www.qtcentre.org/threads/31393-SOLVED-CMake-link-errors-(A-K-A-moc-handling)
Sorry, I didn't find a more adequated section. I think it is possible that the second error (when linking to opengl directly) is because the moc are not being generated, I'll check on that. Thanks.

you ca use:

QT+=coregui+ opengl

in qt file proj.
This is for qmake, not cmake, but thanks.


EDIT: It is solved. The error was indeed that the moc files had not been generated. The correct makefile has glwidget.h in the qt4_wrap_cpp but OpenGL also must be included.

This post has been edited 1 times, last edit by "dyeray" (Jul 7th 2012, 5:17pm)