Results 1 to 2 of 2

Thread: Cmake and opengl - linking error

  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Default Cmake and opengl - linking error

    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:
    Qt Code:
    1. cmake_minimum_required(VERSION 2.6)
    2.  
    3. SET(PROJECTNAME plot)
    4.  
    5. PROJECT(${PROJECTNAME})
    6.  
    7. set(QT_USE_QTOPENGL TRUE)
    8.  
    9. # QT4 Handling
    10. FIND_PACKAGE( Qt4 REQUIRED )
    11.  
    12. INCLUDE(${QT_USE_FILE})
    13.  
    14. set(qtproject_SRCS
    15. main.cpp
    16. window.cpp
    17. glwidget.cpp
    18. )
    19.  
    20.  
    21. SET(foo_MOC_HDRS
    22. glwidget.h
    23. window.h
    24. )
    25.  
    26. # After this call, foo_MOC_SRCS = moc_glwidget.cxx moc_window.cxx
    27. QT4_WRAP_CPP(foo_MOC_SRCS ${foo_MOC_HDRS})
    28.  
    29. ADD_EXECUTABLE(${PROJECTNAME} ${qtproject_SRCS} ${foo_MOC_SRCS})
    30.  
    31. TARGET_LINK_LIBRARIES(${PROJECTNAME} ${QT_LIBRARIES} )
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. Linking CXX executable plot
    2. Undefined symbols:
    3. "_glEnableClientState", referenced from:
    4. GLWidget::paintGL() in glwidget.cpp.o
    5. GLWidget::initializeGL() in glwidget.cpp.o
    6. GLWidget::initializeGL() in glwidget.cpp.o
    7. "_glDisableClientState", referenced from:
    8. GLWidget::paintGL() in glwidget.cpp.o
    9. "_glGenBuffers", referenced from:
    10. GLWidget::initializeGL() in glwidget.cpp.o
    11. GLWidget::initializeGL() in glwidget.cpp.o
    12. "_glEnable", referenced from:
    13. GLWidget::initializeGL() in glwidget.cpp.o
    14. "_glTranslatef", referenced from:
    15. GLWidget::paintGL() in glwidget.cpp.o
    16. "_glVertexPointer", referenced from:
    17. GLWidget::paintGL() in glwidget.cpp.o
    18. GLWidget::paintGL() in glwidget.cpp.o
    19. "_glBindBuffer", referenced from:
    20. GLWidget::paintGL() in glwidget.cpp.o
    21. GLWidget::paintGL() in glwidget.cpp.o
    22. GLWidget::paintGL() in glwidget.cpp.o
    23. GLWidget::initializeGL() in glwidget.cpp.o
    24. "_glBufferData", referenced from:
    25. GLWidget::paintGL() in glwidget.cpp.o
    26. GLWidget::paintGL() in glwidget.cpp.o
    27. GLWidget::initializeGL() in glwidget.cpp.o
    28. "_glClearColor", referenced from:
    29. GLWidget::initializeGL() in glwidget.cpp.o
    30. "_glColorPointer", referenced from:
    31. GLWidget::paintGL() in glwidget.cpp.o
    32. "_glLoadIdentity", referenced from:
    33. GLWidget::resizeGL(int, int)in glwidget.cpp.o
    34. GLWidget::resizeGL(int, int)in glwidget.cpp.o
    35. GLWidget::paintGL() in glwidget.cpp.o
    36. "_gluPerspective", referenced from:
    37. GLWidget::resizeGL(int, int)in glwidget.cpp.o
    38. "_glClear", referenced from:
    39. GLWidget::paintGL() in glwidget.cpp.o
    40. "_glViewport", referenced from:
    41. GLWidget::resizeGL(int, int)in glwidget.cpp.o
    42. "_glMatrixMode", referenced from:
    43. GLWidget::resizeGL(int, int)in glwidget.cpp.o
    44. GLWidget::resizeGL(int, int)in glwidget.cpp.o
    45. "_glDrawElements", referenced from:
    46. GLWidget::paintGL() in glwidget.cpp.o
    47. "_glRotatef", referenced from:
    48. GLWidget::paintGL() in glwidget.cpp.o
    49. GLWidget::paintGL() in glwidget.cpp.o
    50. "_glDrawArrays", referenced from:
    51. GLWidget::paintGL() in glwidget.cpp.o
    52. ld: symbol(s) not found
    53. collect2: ld returned 1 exit status
    54. make[2]: *** [plot] Error 1
    55. make[1]: *** [CMakeFiles/plot.dir/all] Error 2
    56. make: *** [all] Error 2
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Oct 2010
    Posts
    2

    Default Re: Cmake and opengl - linking error

    I found the solution. I have just forgotten to write "FIND_PACKAGE(OpenGL REQUIRED)"

    so my CMakeLists.txt looks like this:
    Qt Code:
    1. #cmake -DQT_QMAKE_EXECUTABLE=/usr/bin/qmake-4.7 CMakeLists.txt
    2.  
    3. cmake_minimum_required(VERSION 2.6)
    4.  
    5. SET(PROJECTNAME plot)
    6.  
    7. PROJECT(${PROJECTNAME})
    8.  
    9. set(qtproject_SRCS
    10. main.cpp
    11. window.cpp
    12. glwidget.cpp
    13. )
    14.  
    15.  
    16. SET(MOC_HEADERS
    17. glwidget.h
    18. window.h
    19. )
    20.  
    21. # Qt4
    22. FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
    23. INCLUDE(${QT_USE_FILE})
    24.  
    25. QT4_WRAP_CPP(MOC_SOURCES ${MOC_HEADERS})
    26. SET(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES})
    27.  
    28. # OpenGL
    29. FIND_PACKAGE(OpenGL REQUIRED)
    30. if(NOT OPENGL_FOUND)
    31. message(ERROR " OPENGL not found!")
    32. endif(NOT OPENGL_FOUND)
    33.  
    34. SET(LIBRARIES ${LIBRARIES} ${OPENGL_LIBRARIES})
    35.  
    36. INCLUDE_DIRECTORIES(${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} )
    37.  
    38. ADD_EXECUTABLE(${PROJECTNAME} ${qtproject_SRCS} ${MOC_SOURCES})
    39.  
    40. TARGET_LINK_LIBRARIES(${PROJECTNAME} ${LIBRARIES})
    To copy to clipboard, switch view to plain text mode 

    Harnz

Similar Threads

  1. Problem when linking a Qt Unit Test with CMake
    By NoRulez in forum Qt Programming
    Replies: 6
    Last Post: 10th June 2010, 17:30
  2. linking the files with openGL code
    By Abeer in forum Newbie
    Replies: 1
    Last Post: 25th May 2010, 01:10
  3. Error while linking libQtCore.so
    By payal in forum Qt Programming
    Replies: 1
    Last Post: 1st March 2010, 06:54
  4. cmake error
    By jd in forum Installation and Deployment
    Replies: 2
    Last Post: 2nd August 2008, 08:22
  5. Linking to wrong version of Qt in Cmake
    By Matt Smith in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2007, 10:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.