我尝试在 qtcreator(windows)中使用 Cmake ,Cmake可以找到提升" 系统"和" 主题"成功,但有一个问题"未定义引用`boost :: system :: generic_category()"在编译时。我搜索了这样的问题,添加" -lboost_system "也许是一个解决方案,但我的项目中没有" .pro" 文件,所以如何在CMakeLists中添加它。 以下是我的CmakeLists的一部分:
project(demo)
cmake_minimum_required(VERSION 2.8.9)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(DEBUG_FLAG _d)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Qml REQUIRED)
find_package(Qt5Declarative)
find_package(OpenGL REQUIRED)
find_package(Boost 1.58 REQUIRED COMPONENTS system thread)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
set(OGRE_RESOURCE_FOLDER ${PROJECT_SOURCE_DIR}/resources)
set(OGRE_HOME "D:/3rd/OGRE")
set(OGRE_PLUGIN_FOLDER "${OGRE_HOME}\\bin")
include_directories(
"${OGRE_HOME}\\include"
"${OGRE_HOME}\\include\\OGRE"
"${OGRE_HOME}\\include\\OGRE\\RenderSystems\\GL"
"${OGRE_HOME}\\boost")
link_directories(${LINK_DIRECORIES} "${OGRE_HOME}\\lib" "${OGRE_HOME}\\lib\\opt")
include_directories("C:/3rd/Eigen" "C:/3rd/robotics/include" "D:/3rd/Eigen" "D:/3rd/robotics/include")
link_directories("C:/3rd/robotics/lib" "D:/3rd/robotics/lib")
add_library(robot src/robot.cpp)
add_library(QOgre src/QOgreWidget.cpp)
qt5_use_modules(QOgre OpenGL Widgets Xml)
add_executable(OGREDemo src/QOgreWidgetDemo.cpp src/ogredemo.cpp )
qt5_use_modules(OGREDemo OpenGL Widgets Xml)
target_link_libraries(OGREDemo ${OPENGL_LIBRARIES} ${BOOST_LINK_LIBS_DEBUG}
OgreMain${DEBUG_FLAG} OIS${DEBUG_FLAG}
orocos-kdl${DEBUG_FLAG} robot QOgre )
file(GLOB_RECURSE QMLS "." "*.qml")
qt5_add_resources(RESOURCES_ADDED resources/qml.qrc)
set_source_files_properties(${RESOURCE_ADDED} PROPERTIES GENERATED ON)
add_executable(recat src/main.cpp src/QmlOgre.cpp ${RESOURCES_ADDED} ${QMLS})
qt5_use_modules(recat Widgets Xml Quick Qml Core Gui Declarative)
target_link_libraries(recat ${OPENGL_LIBRARIES} ${BOOST_LINK_LIBS_DEBUG}
OgreMain${DEBUG_FLAG} OIS${DEBUG_FLAG} RenderSystem_GL${DEBUG_FLAG}
orocos-kdl${DEBUG_FLAG} robot)
configure_file (
"${PROJECT_SOURCE_DIR}/plugins.cfg.in"
"${PROJECT_BINARY_DIR}/plugins.cfg"
)
configure_file (
"${PROJECT_SOURCE_DIR}/resources.cfg.in"
"${PROJECT_BINARY_DIR}/resources.cfg"
)
详细的问题描述:
D:\3rd\robotics_android\src\QOgreWidgetDemo.cpp:-1: error: undefined reference to `boost::system::generic_category()'
error: CMakeFiles\OGREDemo.dir/objects.a(QOgreWidgetDemo.cpp.obj): bad reloc address 0x1b in section `.text$_ZNK5boost6system10error_code7messageEv[__ZNK5boost6system10error_code7messageEv]'
答案 0 :(得分:0)
要链接的正确变量是 Boost_SYSTEM_LIBRARY_DEBUG 。正如@ usr1234567所述,没有必要使用 link_directories 。