在Linux上使用Cmake进行提升(ubuntu)

 懒懒加菲猫爱小狐狸 发布于 2023-01-18 13:09

这是我的CMakeLists.txt档案:

add_definitions(-std=c++11)
find_package(Boost 1.55.0 COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(bst main.cpp)
target_link_libraries(bst ${Boost_LIBRARIES})

当我cmake ..在我的build目录中执行时,cmake成功生成文件.

但是,当我makebuild目录中运行时,我得到以下错误:

amin@aminux:~/Documents/boost_test/build$ make
Scanning dependencies of target bst
[100%] Building CXX object CMakeFiles/bst.dir/main.cpp.o
Linking CXX executable bst
/usr/bin/ld: CMakeFiles/bst.dir/main.cpp.o: undefined reference to    symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.55.0: error   adding       symbols: DSO missing from command line
 collect2: error: ld returned 1 exit status
make[2]: *** [bst] Error 1
make[1]: *** [CMakeFiles/bst.dir/all] Error 2
make: *** [all] Error 2

在我的main.cpp源文件中,我刚刚调用了 boost::filesystem::is_directory函数进行测试 boost.

1 个回答
  • 您还应该在CMakeLists.txt文件中添加boost :: system库组件

    find_package(需要Boost 1.55.0 COMPONENTS文件系统系统)

    2023-01-18 13:11 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有