使用 0.5 libyaml-cpp-dev 构建失败并出现 boost 错误

Posted

技术标签:

【中文标题】使用 0.5 libyaml-cpp-dev 构建失败并出现 boost 错误【英文标题】:Build using 0.5 libyaml-cpp-dev fails with boost errors 【发布时间】:2021-10-05 08:13:42 【问题描述】:

我通过sudo apt install libyaml-cpp-dev 安装了 libyaml-cpp-dev,并在我的机器上安装了 yaml-cpp 0.5 版本。

dpkg -s libyaml-cpp-dev | grep Version
Version: 0.5.2-4ubuntu1

使用这个,我尝试构建一个测试代码,demo.cpp,如下所示:

#include <string>
#include "yaml-cpp/yaml.h"

int main()
  std::string config_file"/home/freyr/exper/yamp-cpp/rvs.conf";
  YAML::Node config = YAML::LoadFile(config_file);
  return 0;

使用 cmake,

cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
find_package(yaml-cpp REQUIRED)
add_executable (helloDemo demo.cpp)
include_directories($YAML_CPP_INCLUDE_DIRS)
target_link_libraries(helloDemo $YAML_CPP_LIBRARIES)

当我尝试构建时,出现以下错误:

make: Entering directory '/home/freyr/exper/yamp-cpp/build' make[1]: Entering directory '/home/freyr/exper/yamp-cpp/build' make[2]: Entering directory '/home/freyr/exper/yamp-cpp/build' Scanning dependencies of target helloDemo make[2]: Leaving directory '/home/freyr/exper/yamp-cpp/build' make[2]: Entering directory '/home/freyr/exper/yamp-cpp/build' [ 50%] Building CXX object CMakeFiles/helloDemo.dir/demo.cpp.o In file included from /usr/include/yaml-cpp/node/iterator.h:13:0,
                 from /usr/include/yaml-cpp/node/impl.h:11,
                 from /usr/include/yaml-cpp/yaml.h:17,
                 from /home/freyr/exper/yamp-cpp/demo.cpp:3: /usr/include/yaml-cpp/node/detail/iterator.h: In member function ‘void YAML::detail::iterator_base<V>::increment()’: /usr/include/yaml-cpp/node/detail/iterator.h:48:54: error: ‘next’ is not a member of ‘boost’    void increment()  this->base_reference() = boost::next(this->base()); 
                                                      ^~~~ /usr/include/yaml-cpp/node/detail/iterator.h:48:54: note: suggested alternatives: In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from /home/freyr/exper/yamp-cpp/demo.cpp:1: /usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:   ‘std::next’
     next(_ForwardIterator __x, typename
     ^~~~ In file included from /usr/local/include/boost/mpl/next.hpp:17:0,
                 from /usr/local/include/boost/mpl/bind.hpp:25,
                 from /usr/local/include/boost/mpl/lambda.hpp:18,
                 from /usr/local/include/boost/mpl/apply.hpp:25,
                 from /usr/local/include/boost/iterator/iterator_facade.hpp:36,
                 from /usr/include/yaml-cpp/node/detail/node_iterator.h:12,
                 from /usr/include/yaml-cpp/node/detail/iterator.h:12,
                 from /usr/include/yaml-cpp/node/iterator.h:13,
                 from /usr/include/yaml-cpp/node/impl.h:11,
                 from /usr/include/yaml-cpp/yaml.h:17,
                 from /home/freyr/exper/yamp-cpp/demo.cpp:3: /usr/local/include/boost/mpl/next_prior.hpp:29:8: note:   ‘boost::mpl::next’  struct next
        ^~~~ CMakeFiles/helloDemo.dir/build.make:62: recipe for target 'CMakeFiles/helloDemo.dir/demo.cpp.o' failed make[2]: *** [CMakeFiles/helloDemo.dir/demo.cpp.o] Error 1 make[2]: Leaving directory '/home/freyr/exper/yamp-cpp/build' CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/helloDemo.dir/all' failed make[1]: *** [CMakeFiles/helloDemo.dir/all] Error 2 make[1]: Leaving directory '/home/freyr/exper/yamp-cpp/build' Makefile:83: recipe for target 'all' failed make: *** [all] Error 2

我在最新的https://github.com/jbeder/yaml-cpp/blob/master/include/yaml-cpp/node/detail/iterator.h 中看到没有提到 boost 广告,它只是 std c++。 如何安装没有 boost 依赖项的最新版本的 libyaml-cpp-dev ?我不想从最新版本构建和安装,因为每次从 master 克隆 git 都不是一个非常安全的做法。

【问题讨论】:

【参考方案1】:

yaml-cpp 在 0.5 版本中引入了 boost 依赖,并在 0.6 版本中删除了它。您需要将 Ubuntu 升级到较新的版本或从源代码安装 yaml-cpp,或安装 yaml-cpp 版本早于 0.5。

见:https://yaml-cpp.docsforge.com/#how-to-build

yaml-cpp 0.6.0 已经发布!此版本需要 C++11,不再依赖 Boost。

另见https://www.ubuntuupdates.org/package/core/hirsute/main/base/yaml-cpp - Ubuntu 21.4 中 yaml-cpp 的当前版本是 0.6.3-9ubuntu1

【讨论】:

在某些无法从 yaml 源克隆的气隙设置中,无法从源安装 yaml-cpp。我正在使用 Ubuntu 18.04,apt 为我提供了 libyaml-0.5,遗憾的是它具有增强依赖项。我正在寻找一种方法来指定使用哪个最新软件包安装的版本。像 libyaml-cpp-dev0.6 或 libyaml-cpp-dev0.6.3-10 这样的附件都不起作用。 Ubuntu 应该可以安装(降级到)较旧的软件包,即 0.4.* 或更早版本。

以上是关于使用 0.5 libyaml-cpp-dev 构建失败并出现 boost 错误的主要内容,如果未能解决你的问题,请参考以下文章

使用maven构建多模块项目_记录

如何从 netatalk 2.0.5 为 opensuse 11.2 创建 RPM 构建

使用 yaml-cpp 0.5 DLL 时的链接器错误

构建用于调整超参数的网格搜索

自定义复合控件在添加回 VGROUP 后仅 0.5-1 秒无法正确呈现

Worklight 5.0.5 生成不可更改的内联 CSS