PDA

View Full Version : Compiling Qt Plugin with CMake issue



postb99
4th March 2014, 11:17
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,

Added after 1 9 minutes:

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}
)

postb99
5th March 2014, 10:46
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@@6BXAppletPlu gin@@@) referenced in function "public: __cdecl tutorial1::AppletTutorial1::AppletTutorial1(void)" (??0AppletTutorial1@tutorial1@@QEAA@XZ)

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.