我无法让 CMake (3.16.4) 和 boost 像他们应该的那样一起工作。
我的系统安装了 boost (v1.72),我编译了另一个版本,如下所示:
wget https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.gz
tar -xf boost_1_71_0.tar.gz
cd boost_1_71_0 && ./bootstrap.sh && ./b2 --prefix=../external/boost_1_71_0 --with-timer install
Run Code Online (Sandbox Code Playgroud)
我有一个使用升压计时器的简单测试程序:
#include <iostream>
int main()
{
boost::timer::auto_cpu_timer t;
std::cout << "Hello Timer" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这就是 CMakeLists.txt:
cmake_minimum_required(VERSION 3.16.4)
Project(CmakeBoostText)
set(Boost_DEBUG 1)
set(Boost_NO_SYSTEM_PATHS ON)
set(BOOST_ROOT ../external/boost_1_71_0)
find_package(Boost 1.71 REQUIRED COMPONENTS timer)
add_executable(main main.cpp)
target_link_libraries(main Boost::timer)
Run Code Online (Sandbox Code Playgroud)
然后我尝试编译我的测试二进制文件:
rm -rf build/* && cmake -S . -B build && cmake --build build
Run Code Online (Sandbox Code Playgroud)
在输出中,您可以清楚地看到他正在使用 boost 的系统变体:
-- [ /usr/share/cmake-3.16/Modules/FindBoost.cmake:1468 …Run Code Online (Sandbox Code Playgroud)