【问题标题】:make fatal error: boost/fusion/iterator/equal_to.hpp no such file or directory造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
【发布时间】:2018-09-05 03:44:13
【问题描述】:

我正在尝试使用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!";

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
project(LOGGER)

set(BOOST_INCLUDEDIR "/path/to/env/include")
set(BOOST_ROOT "/path/to/env/include")

find_package(Boost REQUIRED)

message (STATUS ${Boost_LIBRARIES})

ADD_EXECUTABLE(logger logger.cpp)

target_link_libraries(logger Boost::boost ${Boost_LIBRARIES})

set (CMAKE_CXX_FLAGS "-g -Wall")

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

我在这里做错了什么?我该如何解决?

【问题讨论】:

  • 用-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON 运行cmake查看具体命令,检查包含路径是否设置正确。
  • 您在 CMakeLists.txt 中评论了 #find_package(boost) 行。包名称区分大小写。在add_executable 调用之前将find_package(Boost REQUIRED) 添加到您的CMakeLists.txt。在那个电话之后添加target_link_libraries(logger Boost::boost ${Boost_LIBRARIES})。
  • 您可以在配置期间使用-DBoost_DIR=[path-to-Boost-root] 选项影响find_package(Boost) 命令的搜索(请参阅doc)。但是,这需要包含一个配置文件。
  • 请在您的 CMakeLists.txt 中添加一个 CMake 变量 set(BOOST_ROOT /work/cloudparc/env/include) 并确保您已删除 CMakeCache.txt 文件,否则您的更改可能不适用..
  • 因为您在find_package 调用中没有引用COMPONENTS,所以Boost_LIBRARIES 默认为空。您的 CMake 版本和平台是什么?

标签: c++ boost cmake boost-logging


【解决方案1】:

似乎您实际上并未包含 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 的方法是从 this cmake guide 无耻地复制过来的。

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 2018-02-11
    • 2017-05-09
    • 2021-05-15
    • 2014-10-31
    • 2022-01-11
    • 2021-09-19
    • 2016-06-23
    相关资源
    最近更新 更多