C++ 出现致命错误:boost/fusion/iterator/equal_to.hpp没有这样的文件或目录

C++ 出现致命错误:boost/fusion/iterator/equal_to.hpp没有这样的文件或目录,c++,boost,cmake,boost-logging,C++,Boost,Cmake,Boost Logging,我正在尝试使用cmake编译一个小的boost::logger演示应用程序,但是我的路径没有被正确解释。 这就是我所拥有的: logger.cpp: #include <iostream> #include <boost/fusion/iterator/equal_to.hpp> #include <boost/log/core.hpp> #include <boost/log/trivial.hpp> #include <boost/log

我正在尝试使用
cmake
编译一个小的
boost::logger
演示应用程序,但是我的路径没有被正确解释。 这就是我所拥有的:
logger.cpp

#include <iostream>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;


void init()
{
    logging::add_file_log("sample.log");

    logging::core::get()->set_filter
    (   
        logging::trivial::severity >= logging::trivial::info
    );
}

int main(void) {
    init();

    std::cout <<"Hello World!";
cmake
输出:

$ rm -rf *;cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.67.0
-- 
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:11 (ADD_EXECUTABLE):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "logger" links to target "Boost::boost" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /path/to/src/tmp/logger/build
在编译时,我得到:

$ make
[ 50%] Building CXX object CMakeFiles/logger.dir/logger.cpp.o
/path/to/src/tmp/logger/logger.cpp:4:46: fatal error: boost/fusion/iterator/equal_to.hpp: No such file or directory
compilation terminated.
CMakeFiles/logger.dir/build.make:62: recipe for target 'CMakeFiles/logger.dir/logger.cpp.o' failed
make[2]: *** [CMakeFiles/logger.dir/logger.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/logger.dir/all' failed
make[1]: *** [CMakeFiles/logger.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
即使
equal_to.hpp
位于指定目录中:

$ ls -l /path/to/env/include/boost/fusion/iterator/equal_to.hpp
-rw-rw-rw- 1 ron ron 3330 Apr 17 02:01 /path/to/env/include/boost/fusion/iterator/equal_to.hpp

我做错了什么?我该如何修复它呢?

看起来您实际上没有包括boost所在的目录。 尝试在设置目录变量后添加此行:

target_include_directories(logger BOOST_INCLUDEDIR)

您可能还想考虑将Boost添加为导入目标,例如:

find_package(Boost REQUIRED)
add_library(boost INTERFACE IMPORTED)
set_property(TARGET boost PROPERTY
    INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})

这样,正确的目录将包含在与boost库的链接中。上述将Boost包含在项目中的方法是无耻地从中复制而来的。

使用
-DCMAKE\u VERBOSE\u MAKEFILE:BOOL=ON运行cmake,查看确切的命令,并检查包含路径是否设置正确。您在CMakeLists.txt中注释了行
\find_package(Boost)
。包名称区分大小写。在调用
Add\u executable
之前,将
find\u包(需要Boost)
添加到CMakeLists.txt。在该调用之后添加
target\u link\u libraries(logger Boost::Boost${Boost\u libraries})
。您可以在配置期间使用
-DBoost\u DIR=[path to Boost root]
选项影响
查找包(Boost)
命令的搜索(请参阅)。但是,这需要包含一个配置文件。请将CMake变量
集(BOOST\u ROOT/work/cloudparc/env/include)
添加到您的CMakeLists.txt中,并确保已删除CMakeCache.txt文件,否则您的更改可能不适用。。由于您没有引用
find\u包中的
组件
,因此调用
Boost\u库
默认为空。您的CMake版本和平台是什么?
find_package(Boost REQUIRED)
add_library(boost INTERFACE IMPORTED)
set_property(TARGET boost PROPERTY
    INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})