目前我正在尝试使用 kde4_add_library 创建一个共享库。实际上它是 add_library 还是 kde4_add_library 并不重要,但似乎 add_library 没有任何意义,因为它无法处理带有“Q_OBJECT”宏/moc 文件的类?!不幸的是,对于链接到 kde4 lib 目标的子目录中的共享库类中的许多方法,编译会说“未定义的引用”。错误消息如下所示:
./wc3lib/src/editor/editor.cpp:71: undefined reference to `wc3lib::editor::BlpCodec::startup()'
为了查找包,我使用以下宏:
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 ()
之后添加子目录:
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 ()
它们包含没有任何 KDE 宏的目标:
add_library(Plugin_BlpCodec SHARED ${wc3lib_EDITOR_PLUGIN_BLPCODEC_SRC})
target_link_libraries(Plugin_BlpCodec wc3libblp ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${GETTEXT_LIBRARIES})
现在终于在父目录中创建了 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)
像“EDITOR”这样的 CMake 选项都已启用。对于一个链接库“qblp”,我使用了一些 Qt 的东西:
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
另一个简单地使用“add_library”,并且它本身也有与之链接的系统库。这些依赖项都没有编译失败。方法都定义好了。我用
cmake_minimum_required(VERSION 2.8.4)
kdelibs-4.11.5 qtcore-4.8.5-r1
这不是我第一次通过 CMake 使用 Qt/KDE 时遇到问题。到目前为止有什么帮助吗?
编辑: 请注意,“目标“wc3libeditor”具有与其 LINK_INTERFACE_LIBRARIES 属性不同的 INTERFACE_LINK_LIBRARIES 属性。” 出现 wc3libeditor 目标。这与链接问题有关吗?