如何使用CMake在ubuntu上找到已安装的Boost库
How can I find installed Boost library on ubuntu using CMake?
我使用命令安装了Boost
sudo apt-get install libboost-all-dev
我在main.cpp 中写了这个简单的例子
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
t.wait();
std::cout << "Hello, world!" << std::endl;
return 0;
}
在我的CMakeLists.txt中,我有这样的:
cmake_minimum_required(VERSION 2.8)
find_package(Boost REQUIRED)
if(NOT Boost_FOUND)
message(SEND_ERROR "Failed to find Boost")
return()
else()
include_directories(${Boost_INCLUDE_DIR})
endif()
add_executable(main main.cpp)
CMake工作正常,但在使用make启动后,我出现了一些错误:
main.cpp:(.text+0x11f): undefined reference to `boost::system::generic_category()'
如何在我的CMakeLists.txt中正确地包含boost,以便cmake可以找到库?
您需要针对boost库进行链接。FindBoost为此提供了变量Boost_LIBRARIES
:
add_executable(main main.cpp)
target_link_libraries(main ${Boost_LIBRARIES})
有关更多信息,请参阅FindBoost文档。结尾处有一个例子。
main.cpp:(.text+0x11f): undefined reference to `boost::system::generic_category()'
它在链接步骤失败了。您没有链接到系统库。你需要这样做。
关于CMake使用boost,您没有遇到任何错误。你只需要告诉它这个系统需要连接进来
要在前面的答案基础上添加内容,以下是需要链接的Boost库列表。(截至Boost 1.65(
只需将收割台包括在内,就可以使用所有其他增压库。
相关文章:
- C++:如何在CLion IDE中安装Boost
- 如何在 Mac OS 上安装 boost-mpi 及其对 clang 的依赖关系?
- 在 Windows 10 上安装 Boost 时遇到问题
- 无法在 OS X Sierra 上安装 boost
- boost_signals 使用 brew 安装 boost 时缺少库
- 我是否需要安装Boost来构建odeint
- 非相互互动安装Boost二进制
- 如何在Ubuntu中安装Boost多重任库
- 在Windows 8.1上安装Boost Python,正确设置工具链
- 如何在我的mac上安装boost
- 在macosx上安装boost和PyUblas时出错
- 使用单独的Boost库进行编译,无需安装Boost
- 在 Ubuntu 12.04 中编译并安装 Boost 1.34.1
- 如何在 OSX 中安装 boost
- 安装 boost 会搞砸我的程序吗?
- 从源代码编译后未安装 Boost ptr_container库
- 在 debian 中安装 boost(用于代码块)
- 无法成功安装 Boost.Python
- 在 Mac 上安装 Boost with CodeBlocks
- <dir> 因缺乏而跳过...尝试在 Ubuntu 1.49 上安装 Boost 11.04 时出错