【发布时间】:2020-02-04 07:52:10
【问题描述】:
我想在我的 C++ 代码中使用boost::future:
#include <boost/thread/future.hpp>
boost::future<int> f...
只在C++ 文件中包含标头会导致编译错误:
error: ‘future’ in namespace ‘boost’ does not name a template type
所以我尝试在CMakeLists.txt 文件中包含future:
find_package(Boost COMPONENTS future REQUIRED)
但是,make 命令返回错误:
CMake Error at /usr/local/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Boost (missing: future) (found version "1.71.0")
那么如何从 boost 中包含未来?
【问题讨论】:
-
我想 Boost future 是一个只有标头的库。
COMPONENTS调用的COMPONENTS部分不需要包含 Boost 标头库。 -
您只需将Boost组件添加到
find_package,它们是实际的库。但是 Boost 的许多组件都是仅标头的,因此您可以在源代码中包含标头并使用它。 -
@vre @Simon,你的意思是
find_package(Boost COMPONENTS)?如果我这样做,C++ 代码将无法编译:error: ‘future’ in namespace ‘boost’ does not name a template type -
您仍然需要在代码中包含未来的标头
-
@AlanBirtles,我编辑了这个问题,它包含在...