Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] Compiling Qt Plugin with CMake issue
QtWS25 Last Chance

[SOLVED] Compiling Qt Plugin with CMake issue

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 1 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    postb99
    wrote on last edited by
    #1

    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...

    @#include <QObject>
    #include "XAppletPlugin.h"
    #include "XApplet.h"

    namespace tutorial1 {
    /**

    • @brief AppletTutorial1 plugin class
      */
      class APPLETTUTORIAL1SHARED_EXPORT AppletTutorial1 : public QObject, public XAppletPlugin
      {
      // Q_OBJECT macro should appear in any class derived from QObject
      Q_OBJECT
      // Q_INTERFACES should appear in any class derived from a given interface
      Q_INTERFACES(XAppletPlugin)@

    "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\container-data\XAppletPlugin.h"

    So here is my CMakeLists:

    @cmake_minimum_required(VERSION 2.8.8)

    project(applettutorial1)

    FIND_PACKAGE(Qt4 REQUIRED)

    application headers files

    SET(applettutorial1_HEADERS
    "include/applettutorial1.h"
    "include/applet-tutorial1_global.h"
    "include/applettutorial1imp.h"
    )

    application files: source and headers again

    so that they show up in project files tree

    SET(applettutorial1_SOURCES
    ${applettutorial1_HEADERS}
    src/applettutorial1.cpp
    src/applettutorial1imp.cpp
    tutorial1.xml
    )

    MESSAGE(STATUS "Source files: " ${applettutorial1_SOURCES} )

    Required

    QT4_WRAP_CPP(applettutorial1_HEADERS_MOC ${applettutorial1_HEADERS})

    SET(applettutorial1_RESOURCES images.qrc)

    #QT4_ADD_RESOURCES(applettutorial1_RESOURCES_RCC ${applettutorial1_RESOURCES})

    if (QT4_FOUND)

    SET(QT_USE_QTDESIGNER ON)

    INCLUDE(${QT_USE_FILE})
    ADD_DEFINITIONS(${QT_DEFINITIONS})
    

    else()
    message(FATAL_ERROR "No Qt4 found")
    endif()

    IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
    SET(EXTERNALLIB_BASE "$ENV{EXTERNALLIB}/debug")
    ELSE()
    SET(EXTERNALLIB_BASE "$ENV{EXTERNALLIB}/relWithDebInfo")
    ENDIF()

    MESSAGE(STATUS "EXTERNALLIB base dir: " ${EXTERNALLIB_BASE} )

    EXTERNALLIB version

    SET(VERSION "0.24.0")

    EXTERNALLIB includes

    include_directories(
    "${CMAKE_CURRENT_SOURCE_DIR}/include"
    "${EXTERNALLIB_BASE}/include"
    "${EXTERNALLIB_BASE}/include/container-data"
    )

    link_directories("${EXTERNALLIB_BASE}/lib")

    executable then list of files

    add_executable(
    applettutorial1
    ${applettutorial1_SOURCES}
    ${applettutorial1_HEADERS_MOC}

    ${applettutorial1_RESOURCES_RCC}

    )

    target_link_libraries(
    applettutorial1
    ${QT_LIBRARIES}
    container-data
    )@

    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,

    1 Reply Last reply
    0
    • P Offline
      P Offline
      postb99
      wrote on last edited by
      #2

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

      @# name, type then list of files
      add_library(
      applettutorial1 SHARED
      ${applettutorial1_SOURCES}
      ${applettutorial1_HEADERS_MOC}

      ${applettutorial1_RESOURCES_RCC}

      )@

      1 Reply Last reply
      0
      • P Offline
        P Offline
        postb99
        wrote on last edited by
        #3

        Better use:
        @SET (CMAKE_AUTOMOC ON)@

        rather than old way of using:
        @QT4_WRAP_CPP@

        But then I still have linkage errors:
        @
        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)@

        This page needs to be updated/added to wiki and updated/better referenced too...

        1 Reply Last reply
        0
        • P Offline
          P Offline
          postb99
          wrote on last edited by
          #4

          Solved by including the right headers (there was a check against CMAKE_BUILD_TYPE) and building as STATIC instead of SHARED... Wow.

          Now I'm going to see execution part.

          @cmake_minimum_required(VERSION 2.8.8)

          project(applettutorial1)

          FIND_PACKAGE(Qt4 REQUIRED)

          application headers files

          SET(applettutorial1_HEADERS
          "include/applettutorial1.h"
          "include/applet-tutorial1_global.h"
          "include/applettutorial1imp.h"
          "include/TestInterface.h"
          )

          application files: source and headers again

          so that they show up in project files tree

          SET(applettutorial1_SOURCES
          ${applettutorial1_HEADERS}
          src/applettutorial1.cpp
          src/applettutorial1imp.cpp
          tutorial1.xml
          )

          MESSAGE(STATUS "Source files: " ${applettutorial1_SOURCES} )

          SET (CMAKE _AUTOMOC ON)

          if (QT4_FOUND)
          INCLUDE(${QT_USE_FILE})
          else()
          message(FATAL_ERROR "No Qt4 found")
          endif()

          MESSAGE(STATUS "QT_USE_FILE: " ${QT_USE_FILE} )

          IF(CMAKE_BUILD_TYPE MATCHES Debug)
          SET(EXTERNALLIB_BASE "$ENV{EXTERNALLIB}/debug")
          MESSAGE(STATUS "Debug build")
          ELSE()
          SET(EXTERNALLIB_BASE "$ENV{EXTERNALLIB}/relWithDebInfo")
          MESSAGE(STATUS "Not debug build")
          ENDIF()

          MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE} )

          MESSAGE(STATUS "EXTERNALLIB base dir: " ${EXTERNALLIB_BASE} )

          EXTERNALLIB version

          SET(VERSION "0.24.0")

          includes

          include_directories(
          "${CMAKE_CURRENT_SOURCE_DIR}/include"
          "${EXTERNALLIB_BASE}/include"
          "${EXTERNALLIB_BASE}/include/foundation"
          ${CMAKE_CURRENT_BINARY_DIR}
          ${QT_QTCORE_INCLUDE_DIR}
          ${QT_INCLUDE_DIR}
          )

          link_directories("${EXTERNALLIB_BASE}/lib")

          name, type then list of files

          add_library(
          applettutorial1 STATIC
          ${applettutorial1_SOURCES}
          ${applettutorial1_HEADERS}
          )

          target_link_libraries(
          applettutorial1
          ${QT_LIBRARIES}
          foundation
          )

          #install...
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved