代码之家  ›  专栏  ›  技术社区  ›  patrick

从boost::绑定1和2占位符运行make失败。。。?

  •  1
  • patrick  · 技术社区  · 1 年前

    我正在尝试运行make来构建一个项目,我得到了:

    In file included from validation.cpp:46:
    In file included from /opt/homebrew/opt/boost/include/boost/math/distributions/poisson.hpp:40:
    In file included from /opt/homebrew/opt/boost/include/boost/math/special_functions/gamma.hpp:17:
    In file included from /opt/homebrew/opt/boost/include/boost/math/tools/series.hpp:16:
    /opt/homebrew/opt/boost/include/boost/math/tools/config.hpp:23:6: warning: "The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)" [-W#warnings]
    #    warning "The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)"
         ^
    validation.cpp:173:111: error: use of undeclared identifier '_1'
            pool.NotifyEntryRemoved.connect(boost::bind(&MemPoolConflictRemovalTracker::NotifyEntryRemoved, this, _1, _2));
                                                                                                                  ^
    validation.cpp:173:115: error: use of undeclared identifier '_2'
            pool.NotifyEntryRemoved.connect(boost::bind(&MemPoolConflictRemovalTracker::NotifyEntryRemoved, this, _1, _2));
                                                                                                                      ^
    validation.cpp:183:114: error: use of undeclared identifier '_1'
            pool.NotifyEntryRemoved.disconnect(boost::bind(&MemPoolConflictRemovalTracker::NotifyEntryRemoved, this, _1, _2));
                                                                                                                     ^
    validation.cpp:183:118: error: use of undeclared identifier '_2'
            pool.NotifyEntryRemoved.disconnect(boost::bind(&MemPoolConflictRemovalTracker::NotifyEntryRemoved, this, _1, _2));
                                                                                                                         ^
    1 warning and 4 errors generated.
    make[2]: *** [libbitcoin_server_a-validation.o] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all-recursive] Error 1
    

    编译器为什么抱怨 _1 _2 ?

    我在以下位置阅读了故障排除文档: https://www.boost.org/doc/libs/1_64_0/libs/bind/doc/html/bind.html#bind.troubleshooting.msvc_specific_using_boost_bind

    但我看不到任何关于这个问题的信息,也看不到如何解决它。

    1 回复  |  直到 1 年前
        1
  •  0
  •   sehe    1 年前

    为什么编译器抱怨_1和_2?

    你没有显示你的代码。然而,消息引用了以下几行:

    pool.NotifyEntryRemoved.connect(boost::bind(&MemPoolConflictRemovalTracker::NotifyEntryRemoved, this, _1, _2));
    pool.NotifyEntryRemoved.disconnect(boost::bind(&MemPoolConflictRemovalTracker::NotifyEntryRemoved, this, _1, _2));
    

    现在,自从 _1 _2 没有找到,你知道它缺少资格 boost::placeholders::_1 或类似的using指令

    using namespace boost::placeholders;
    

    请注意,在(非常!)旧版本的Boost中,占位符只在全局命名空间中。对于包括即将发布的1.83.0版本在内的一长系列版本,如果包含旧版标题,仍然会警告此更改

    #include <boost/bind.hpp>
    

    而不是新位置:

    #include <boost/bind/bind.hpp>
    

    您将看到以下警告:

    BOOST_PRAGMA_MESSAGE(
      "The practice of declaring the Bind placeholders (_1, _2, ...) "
      "in the global namespace is deprecated. Please use "
      "<boost/bind/bind.hpp> + using namespace boost::placeholders, "
      "or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior."
    )
    

    正如你所看到的,这给了你 另一种 补救措施,我不会推荐。显然,您正在使用的库将它们的实现切换到了名称空间更干净的版本,并且您的代码默默地依赖于不推荐使用的全局占位符。