我已經使用這個命令如何在使用CMake的ubuntu上找到已安裝的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正常工作,但啓動後使我有一些錯誤:
main.cpp:(.text+0x11f): undefined reference to `boost::system::generic_category()'
如何在我的CMakeLists.txt中正確包含boost以便cmake能夠找到庫?
確保您的CMake版本足夠新:https://stackoverflow.com/a/42124857/2799037 – usr1234567