所以,我正在尝试为学校编写一个applet,其中一部分需要使用cmake。我有两个不同的类包含在他们自己的文件中,我将它们用作主类的一部分。我在主项目标题中包含了它们的标题:
#include /path/to/header/1.h
#include /path/to/header/2.h
我遇到的问题是,当我运行cmake之后运行make时,我会在尝试使用两个库中的一个的任何实例中获得未定义的引用错误。我知道它与链接器错误有关,但由于我是cmake的新手,我不确定使用TARGET_LINK_LIBRARIES的正确方法是什么。
修改
在链接/关联我的库之后,我有以下内容:
的CMakeLists.txt:
# A name for the project
project(plasma-engine-gdrive)
# Find the required libaries
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}, -std=c++0x)
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${KDE4_INCLUDES}
./include
./lib
)
set (GOOGLE_LIBS include/atom_helper.h include/util/string_utils.h include/client/doc_list_service.h include/client/service.h)
set (GOOGLE_SRCS include/atom_helper.cc include/util/string_utils.cc include/client/doc_list_service.cc include/client/service.cc)
# We add our source code here
set(gdrive_engine_SRCS gdriveengine.cpp)
add_library (DataWrapper include/DataWrapper.cpp include/DataWrapper.h)
add_library (GData ${GOOGLE_SRCS} ${GOOGLE_LIBS})
# Now make sure all files get to the right place
kde4_add_plugin(plasma_engine_gdrive ${gdrive_engine_SRCS})
target_link_libraries(plasma_engine_gdrive
GData
DataWrapper
${KDE4_KDECORE_LIBS}
${KDE4_PLASMA_LIBS})
install(TARGETS plasma_engine_gdrive
DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES plasma-engine-gdrive.desktop
DESTINATION ${SERVICES_INSTALL_DIR})
此处还有太多错误。这里有几个:
/usr/include/c++/4.6/bits/stl_map.h:467: undefined reference to `Glib::ustring::ustring()'
lib/libGData.a(atom_helper.o): In function `pair<Glib::ustring, Glib::ustring, void>':
/usr/include/c++/4.6/bits/stl_pair.h:132: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
/usr/include/c++/4.6/bits/stl_pair.h:132: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
lib/libGData.a(atom_helper.o): In function `pair<Glib::ustring, Glib::ustring>':
/usr/include/c++/4.6/bits/stl_pair.h:137: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
/usr/include/c++/4.6/bits/stl_pair.h:137: undefined reference to `Glib::ustring::ustring(Glib::ustring const&)'
答案 0 :(得分:8)
我和其他人一起工作,我把它编译好了!
我真正需要的是提供库的名称并将其放入target_link_libraries
中,如下所示:
target_link_libraries(plasma_engine_gdrive
DataWrapper
GData
xml++-2.6
curl
glibmm-2.4
${KDE4_KDECORE_LIBS}
${KDE4_PLASMA_LIBS})
我的爸爸,完全不熟悉CMake,去了CMake构建结构中的link.txt
。在那里,他刚刚在-o
标志后添加了以下内容:
-lxml++-2.6
-lcurl
-lglibmm-2.4
当我看到它时,我想我可能会尝试通过CMakeLists.txt进行链接 - 而且它有效。