【发布时间】:2017-08-28 20:19:16
【问题描述】:
我已经使用这个命令安装了 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 找到库?
【问题讨论】:
-
确保您的 CMake 版本足够新:stackoverflow.com/a/42124857/2799037