質問

at the moment I am trying to create a shared library using kde4_add_library. Actually it does not matter if it is add_library or kde4_add_library but it seems that add_library makes no sense since it cannot handle classes with "Q_OBJECT" macros/moc files?! Unfortunately compiling says "undefined reference" for many methods from classes of shared libraries in sub directories which are linked against the kde4 lib target. The error messages look like:

 ./wc3lib/src/editor/editor.cpp:71: undefined reference to `wc3lib::editor::BlpCodec::startup()'

For finding the packages I use the following macros:

if (EDITOR)
    find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
elseif (PLUGINS)
    find_package(Qt4 COMPONENTS QtCore QtGui)
endif ()

if (${QT4_FOUND})
    include(${QT_USE_FILE})
    add_definitions(${QT_DEFINITIONS})
    include_directories(${QT_INCLUDE_DIR})
endif ()

if (EDITOR)
    find_package(KDE4 REQUIRED)
elseif (PLUGINS)
    find_package(KDE4) # only for MPQ plugins
endif ()

if (${KDE4_FOUND})
    include(KDE4Defaults)
    add_definitions(${KDE4_DEFINITIONS})
    include_directories(${KDE4_INCLUDE_DIR} ${KDE4_INCLUDES})
    link_directories(${KDE4_LIB_DIR})
endif ()

  find_package(OGRE COMPONENTS Paging Terrain REQUIRED)

if (${OGRE_FOUND})
    include_directories(${OGRE_INCLUDE_DIRS})
    link_directories(${OGRE_LIB_DIR})
endif ()

the sub directories are added after that:

 if (BLP AND ${OGRE_FOUND})
add_subdirectory(Plugin_BlpCodec)
 endif ()
 if (MPQ AND ${KDE4_FOUND})
add_subdirectory(kio_mpq)
 endif ()
 if (BLP AND ${QT4_FOUND})
add_subdirectory(qblp)
 endif ()

they contain targets without any KDE macros:

 add_library(Plugin_BlpCodec SHARED ${wc3lib_EDITOR_PLUGIN_BLPCODEC_SRC})
 target_link_libraries(Plugin_BlpCodec wc3libblp ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${GETTEXT_LIBRARIES})

now finally in the parent directory the KDE target is created:

 kde4_add_library(wc3libeditor SHARED ${wc3lib_EDITOR_SRC} ${wc3lib_EDITOR_UI_H})
 target_link_libraries(wc3libeditor ${wc3lib_CORE_LIBRARIES} ${GETTEXT_LIBRARIES} ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${QT_LIBRARIES} ${KDE4_KIO_LIBS} ${KDE4_KUTILS_LIBS} ${KDE4_KPARTS_LIBS} Plugin_BlpCodec qblp)

the CMake options like "EDITOR" are all enabled. For the one linked library "qblp" I use some Qt stuff:

 add_definitions(${QT_DEFINITIONS})
 add_definitions(-DQT_PLUGIN)
 add_definitions(-DQT_SHARED)

the other one simply uses "add_library" and has itself also system libs linked against it. None of these dependencies fails to compile. The methods are all defined. I use

 cmake_minimum_required(VERSION 2.8.4)

kdelibs-4.11.5 qtcore-4.8.5-r1

this is not the first time I have problems using Qt/KDE via CMake. Any help so far?

edit: Note that "Target "wc3libeditor" has an INTERFACE_LINK_LIBRARIES property which differs from its LINK_INTERFACE_LIBRARIES properties." appear for the wc3libeditor target. Is this related to the linking issues?

役に立ちましたか?

解決

So the problem seems to be that

find_package(KDE4 REQUIRED)

adds various C++ flags. You can find all this in /usr/share/apps/cmake/modules/FindKDE4Internal.cmake Some of these flags lead to the undefined reference errors. A simple workaround might be adding

set(CMAKE_CXX_FLAGS "")

after the find_package statement which is kind of ugly.

More information can be found here: http://lists.kde.org/?l=kde-buildsystem&m=132906487119016

and there is a better solution using the export macro: https://forum.kde.org/viewtopic.php?f=64&t=89265

Another solution might be using KDE Frameworks (5) instead.

I've also created a bug report: https://bugs.kde.org/show_bug.cgi?id=338151

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top