Results 1 to 3 of 3

Thread: CMake :Undefined reference for a QObject class

  1. #1
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default CMake :Undefined reference for a QObject class

    Hello all
    I have an linking issue when compiling a programm under linux 32 bit that is using a dynamic library
    My library is a class inheriting QObject and it has the Q_OBEJCT macro inside the classe.

    The problem is that it says "undefined reference" to all signals I have for this class (and only the signals)
    I suspect something I have to change in one or the other CMake but I can t find what even after googling.
    I also suspect it would be due to the "Q_OBJECT" macro..

    the cmake lists of the library is the following

    Qt Code:
    1. cmake_minimum_required(VERSION 2.6)
    2. project(copy_playlist_backend)
    3. set(LIBRARY_OUTPUT_PATH lib)
    4. find_package(Qt4 REQUIRED)
    5. INCLUDE(${QT_USE_FILE})
    6.  
    7. ADD_DEFINITIONS(${QT_DEFINITIONS}) # I have added those four lines after googling but i am not sure what it does.....
    8. ADD_DEFINITIONS(-DQT_PLUGIN)
    9. ADD_DEFINITIONS(-DQT_NO_DEBUG)
    10. ADD_DEFINITIONS(-DQT_SHARED)
    11.  
    12. include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} include)
    13. SET (copy_playlist_backend_SRCS src/*)
    14. SET (copy_playlist_backend_HEADERS ../include/*)
    15.  
    16. file(GLOB_RECURSE source_files ${copy_playlist_backend_SRCS})
    17.  
    18. qt4_wrap_cpp(copy_playlist_backend_HEADERS_MOC ${copy_playlist_backend_HEADERS})
    19. qt4_automoc(${copy_playlist_backend_SRCS}${copy_playlist_backend_HEADERS_MOC})
    20.  
    21. add_library(copy_playlist_backend SHARED ${source_files} )
    To copy to clipboard, switch view to plain text mode 

    the cmake of the executable ist the following

    Qt Code:
    1. cmake_minimum_required(VERSION 2.6)
    2. enable_language(CXX)
    3. PROJECT(Rainyday)
    4. FIND_PACKAGE(Qt4 REQUIRED)
    5. SET (QT_USE_QTXMLPATTERNS)
    6.  
    7. SET (project_name_VERSION_MAJOR 0) # The MAJOR version number.
    8. SET (project_name_VERSION_MINOR 1) # The MINOR version number
    9.  
    10. SET (CPB_INCLUDE /home/max/Documents/C/Library/copy_playlist_backend/include) #directory that contain the .h file of the library i want to link
    11.  
    12. INCLUDE_DIRECTORIES(${CPB_INCLUDE} ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${QT_QTXML_INCLUDE_DIR} ${QT_QTXMLPATTERNS_INCLUDE_DIR})
    13.  
    14. SET(Rainyday_SOURCES main.cpp mainwindow.cpp) # collect the sources of the project and call the collected set "project_name_SRCS"
    15. SET(Rainyday_HEADERS mainwindow.h ui_mainwindow.h)
    16. SET(Rainyday_FORMS mainwindow.ui)
    17. SET(Rainyday_RCCS playlist_ressource.qrc)
    18.  
    19. QT4_WRAP_CPP(Rainyday_HEADERS_MOC ${Rainyday_HEADERS})
    20. QT4_WRAP_UI(Rainyday_FORMS_HEADERS ${Rainyday_FORMS})
    21. QT4_ADD_RESOURCES(Rainyday_RCC_SRCS ${Rainyday_RCCS})
    22. INCLUDE(${QT_USE_FILE})
    23. ADD_DEFINITIONS(${QT_DEFINITIONS})
    24. LINK_DIRECTORIES(/home/max/Documents/C/Library/lib/) # Directory that contain the .so file
    25.  
    26. qt4_automoc(${Rainyday_SOURCES} ${Rainyday_HEADERS_MOC} ${Rainyday_RCC_SRCS} ${Rainyday_FORMS_HEADERS} ${Rainyday_FORMS} )
    27. add_executable(Rainyday ${Rainyday_SOURCES} ${Rainyday_HEADERS_MOC} ${Rainyday_RCC_SRCS} ${Rainyday_FORMS_HEADERS} ${Rainyday_FORMS} )
    28. target_link_libraries(Rainyday ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTXMLPATTERNS_LIBRARY} /home/max/Documents/C/Library/lib/libcopy_playlist_backend.so)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CMake :Undefined reference for a QObject class

    Uping ? just in case of..

  3. #3
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CMake :Undefined reference for a QObject class

    Well I finallly managed to get it thanks to http://qtnode.net/wiki/Qt4_with_cmake

    So this is a template of CMakeLists.txt for a classe called "MACLASSE" that would inherit from QObject (which was the problem because you then have to use QT_WRAPP_CPP
    Qt Code:
    1. cmake_minimum_required(VERSION 2.6)
    2. project(MACLASSE)
    3. set(LIBRARY_OUTPUT_PATH lib)
    4. find_package(Qt4 REQUIRED)
    5. INCLUDE(${QT_USE_FILE})
    6. include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} include)
    7.  
    8. SET (MACLASSE_SRCS src/MACLASSE.cpp)
    9. SET (MACLASSE_HEADERS include/MACLASSE.h)
    10.  
    11. MESSAGE( STATUS "sources: " ${MACLASSE_SRCS} )
    12. MESSAGE( STATUS "headers: " ${MACLASSE_HEADERS} )
    13.  
    14. qt4_wrap_cpp(MACLASSE_HEADERS_MOC ${MACLASSE_HEADERS}) #in there you put the headers and ONLY the headers
    15.  
    16. add_library(MACLASSE SHARED ${MACLASSE_SRCS} ${MACLASSE_HEADERS_MOC} )
    17. target_link_libraries(MACLASSE ${QT_LIBRARIES})
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. undefined reference to `QUiLoader::QUiLoader(QObject*)'
    By ashukla in forum Qt Programming
    Replies: 7
    Last Post: 7th October 2011, 18:05
  2. QOBJECT and undefined reference to vtable errors
    By stargazer in forum Qt Programming
    Replies: 7
    Last Post: 25th April 2011, 05:29
  3. undefined reference to vtable in class
    By JeanC in forum Qt Programming
    Replies: 7
    Last Post: 26th February 2011, 10:23
  4. Replies: 1
    Last Post: 5th February 2011, 03:04
  5. undefined reference to QObject
    By hcerny in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 16:55

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.