简体   繁体   English

CMake:将库链接到KDE4库时未定义的引用

[英]CMake: undefined reference when linking libraries to KDE4 lib

at the moment I am trying to create a shared library using kde4_add_library. 目前,我正在尝试使用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?! 实际上,它是add_library还是kde4_add_library都没有关系,但是add_library似乎没有意义,因为它无法处理带有“ Q_OBJECT”宏/ moc文件的类? Unfortunately compiling says "undefined reference" for many methods from classes of shared libraries in sub directories which are linked against the kde4 lib target. 不幸的是,对于与kde4 lib目标链接的子目录中的共享库类,编译方法对许多方法说“未定义的引用”。 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: 它们包含没有任何KDE宏的目标:

 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: 现在终于在父目录中创建了KDE目标:

 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. CMake选项(例如“ EDITOR”)都已启用。 For the one linked library "qblp" I use some Qt stuff: 对于一个链接库“ qblp”,我使用一些Qt的东西:

 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. 另一个仅使用“ add_library”,并且自身也链接有系统库。 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 kdelibs-4.11.5 qtcore-4.8.5-r1

this is not the first time I have problems using Qt/KDE via CMake. 这不是我第一次通过CMake使用Qt / KDE时遇到问题。 Any help so far? 到目前为止有帮助吗?

edit: Note that "Target "wc3libeditor" has an INTERFACE_LINK_LIBRARIES property which differs from its LINK_INTERFACE_LIBRARIES properties." 编辑:请注意“目标” wc3libeditor“具有一个INTERFACE_LINK_LIBRARIES属性,不同于其LINK_INTERFACE_LIBRARIES属性。 appear for the wc3libeditor target. 出现在wc3libeditor目标上。 Is this related to the linking issues? 这与链接问题有关吗?

So the problem seems to be that 所以问题似乎是

find_package(KDE4 REQUIRED)

adds various C++ flags. 添加了各种C ++标志。 You can find all this in /usr/share/apps/cmake/modules/FindKDE4Internal.cmake Some of these flags lead to the undefined reference errors. 您可以在/usr/share/apps/cmake/modules/FindKDE4Internal.cmake中找到所有这些标记,其中的某些标记会导致未定义的引用错误。 A simple workaround might be adding 一个简单的解决方法可能是添加

set(CMAKE_CXX_FLAGS "")

after the find_package statement which is kind of ugly. 在find_package语句之后,这有点丑陋。

More information can be found here: http://lists.kde.org/?l=kde-buildsystem&m=132906487119016 可以在此处找到更多信息: 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 并且使用导出宏有更好的解决方案: https : //forum.kde.org/viewtopic.php?f=64&t=89265

Another solution might be using KDE Frameworks (5) instead. 另一种解决方案可能是使用KDE Frameworks(5)。

I've also created a bug report: https://bugs.kde.org/show_bug.cgi?id=338151 我还创建了一个错误报告: https : //bugs.kde.org/show_bug.cgi?id=338151

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM