Results 1 to 2 of 2

Thread: Compiling Qt Plugin with CMake issue

  1. #1
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Compiling Qt Plugin with CMake issue

    Hello,

    I am switching my .pro project to CMake.

    It's a Qt 4 custom plugin.

    For now it doesn't build, it complains here: "undefined interface" where I do Q_INTERFACES...

    Qt Code:
    1. #include <QObject>
    2. #include "XAppletPlugin.h"
    3. #include "XApplet.h"
    4.  
    5. namespace tutorial1 {
    6. /**
    7.  * @brief AppletTutorial1 plugin class
    8.  */
    9. class APPLETTUTORIAL1SHARED_EXPORT AppletTutorial1 : public QObject, public XAppletPlugin
    10. {
    11. // Q_OBJECT macro should appear in any class derived from QObject
    12. Q_OBJECT
    13. // Q_INTERFACES should appear in any class derived from a given interface
    14. Q_INTERFACES(XAppletPlugin)
    To copy to clipboard, switch view to plain text mode 

    "XAppletPlugin.h" is correctly found and include isn't in error, only "Q_INTERFACES" line If I hover with the mouse on include lines at top I see the full path of file as tooltip and it's OK: "C:\myExternalLib\relWithDebInfo\include\conta iner-data\XAppletPlugin.h"

    So here is my CMakeLists:

    Qt Code:
    1. cmake_minimum_required(VERSION 2.8.8)
    2.  
    3. project(applettutorial1)
    4.  
    5. FIND_PACKAGE(Qt4 REQUIRED)
    6.  
    7. # application headers files
    8. SET(applettutorial1_HEADERS
    9. "include/applettutorial1.h"
    10. "include/applet-tutorial1_global.h"
    11. "include/applettutorial1imp.h"
    12. )
    13. # application files: source and headers again
    14. # so that they show up in project files tree
    15. SET(applettutorial1_SOURCES
    16. ${applettutorial1_HEADERS}
    17. src/applettutorial1.cpp
    18. src/applettutorial1imp.cpp
    19. tutorial1.xml
    20. )
    21.  
    22. MESSAGE(STATUS "Source files: " ${applettutorial1_SOURCES} )
    23.  
    24. # Required
    25. QT4_WRAP_CPP(applettutorial1_HEADERS_MOC ${applettutorial1_HEADERS})
    26.  
    27. # SET(applettutorial1_RESOURCES images.qrc)
    28. #QT4_ADD_RESOURCES(applettutorial1_RESOURCES_RCC ${applettutorial1_RESOURCES})
    29.  
    30. if (QT4_FOUND)
    31. # SET(QT_USE_QTDESIGNER ON)
    32. INCLUDE(${QT_USE_FILE})
    33. ADD_DEFINITIONS(${QT_DEFINITIONS})
    34. else()
    35. message(FATAL_ERROR "No Qt4 found")
    36. endif()
    37.  
    38. IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
    39. SET(EXTERNALLIB_BASE "$ENV{EXTERNALLIB}/debug")
    40. ELSE()
    41. SET(EXTERNALLIB_BASE "$ENV{EXTERNALLIB}/relWithDebInfo")
    42. ENDIF()
    43.  
    44. MESSAGE(STATUS "EXTERNALLIB base dir: " ${EXTERNALLIB_BASE} )
    45.  
    46.  
    47. # EXTERNALLIB version
    48. SET(VERSION "0.24.0")
    49.  
    50. # EXTERNALLIB includes
    51. include_directories(
    52. "${CMAKE_CURRENT_SOURCE_DIR}/include"
    53. "${EXTERNALLIB_BASE}/include"
    54. "${EXTERNALLIB_BASE}/include/container-data"
    55. )
    56.  
    57. link_directories("${EXTERNALLIB_BASE}/lib")
    58.  
    59. # executable then list of files
    60. add_executable(
    61. applettutorial1
    62. ${applettutorial1_SOURCES}
    63. ${applettutorial1_HEADERS_MOC}
    64. # ${applettutorial1_RESOURCES_RCC}
    65. )
    66.  
    67. target_link_libraries(
    68. applettutorial1
    69. ${QT_LIBRARIES}
    70. container-data
    71. )
    To copy to clipboard, switch view to plain text mode 

    In my code there is no "Q_EXPORT_PLUGIN2" because this is managed by the external lib I use, which acts as a plugin host.

    Thanks,


    Added after 1 9 minutes:


    I've changed "add_executable" to the following but I didn't solve the error for now.

    Qt Code:
    1. # name, type then list of files
    2. add_library(
    3. applettutorial1 SHARED
    4. ${applettutorial1_SOURCES}
    5. ${applettutorial1_HEADERS_MOC}
    6. # ${applettutorial1_RESOURCES_RCC}
    7. )
    To copy to clipboard, switch view to plain text mode 
    Last edited by postb99; 4th March 2014 at 11:17.

  2. #2
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default [SOLVED] Compiling Qt custom plugin with CMake issue

    Better use:
    Qt Code:
    1. SET (CMAKE_AUTOMOC ON)
    To copy to clipboard, switch view to plain text mode 

    rather than old way of using:
    Qt Code:
    1. QT4_WRAP_CPP
    To copy to clipboard, switch view to plain text mode 

    But then I still have linkage errors:
    Qt Code:
    1. applettutorial1.cpp.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) const tutorial1::AppletTutorial1::`vftable'{for `XAppletPlugin'}" (__imp_??_7AppletTutorial1@tutorial1@@6BXAppletPlugin@@@) referenced in function "public: __cdecl tutorial1::AppletTutorial1::AppletTutorial1(void)" (??0AppletTutorial1@tutorial1@@QEAA@XZ)
    To copy to clipboard, switch view to plain text mode 

    Any way to change thread title to "Compiling Qt Plugin with CMake issue" ? I cannot edit my thread base post anymore...


    Added after 55 minutes:


    Solved by including the right headers (there was a check against CMAKE_BUILD_TYPE) and building as STATIC instead of SHARED.
    Last edited by postb99; 5th March 2014 at 10:47. Reason: changed title

Similar Threads

  1. Replies: 6
    Last Post: 25th June 2013, 21:13
  2. cmake moc undefined reference issue
    By dvlpr in forum General Programming
    Replies: 1
    Last Post: 22nd December 2012, 15:28
  3. Compiling QT4 Code using cmake 2.6
    By Serenity in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2008, 19:04
  4. CMake Windows console issue
    By IndigoJo in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2008, 22:12
  5. compiling qt4 applications with cmake
    By elcuco in forum Qt Programming
    Replies: 3
    Last Post: 14th October 2006, 16:51

Tags for this Thread

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.