【问题标题】:boost::date_time error while building MongoDB: winapi is not member构建 MongoDB 时出现 boost::date_time 错误:winapi 不是成员
【发布时间】:2019-04-14 03:53:50
【问题描述】:

在使用 SCons 和 boost 构建 MongoDB 时,我遇到了错误。这是我的命令行:

C:\mongo-cxx-driver>Scons --prefix=$HOME/mongo-client-lib --cpppath=C:\boost_1_66_0 --libpath=C:\boost_1_66_0\stage64\lib --dbg=on --64 安装

以下是我收到的错误消息:

src\mongo\util\time_support.cpp(904): error C2039: 'winapi': is not a member of 'boost::date_time'
C:\boost_1_66_0\boost/date_time/filetime_functions.hpp(28): note: see declaration of 'boost::date_time'
src\mongo\util\time_support.cpp(904): error C3083: 'winapi': the symbol to the left of a '::' must be a type
src\mongo\util\time_support.cpp(904): error C2039: 'file_time_to_microseconds': is not a member of 'boost::date_time'
C:\boost_1_66_0\boost/date_time/filetime_functions.hpp(28): note: see declaration of 'boost::date_time'
src\mongo\util\time_support.cpp(904): error C3861: 'file_time_to_microseconds': identifier not found
src\mongo\util\time_support.cpp(936): error C2039: 'winapi': is not a member of 'boost::date_time'
C:\boost_1_66_0\boost/date_time/filetime_functions.hpp(28): note: see declaration of 'boost::date_time'
src\mongo\util\time_support.cpp(936): error C3083: 'winapi': the symbol to the left of a '::' must be a type
src\mongo\util\time_support.cpp(936): error C2039: 'file_time_to_microseconds': is not a member of 'boost::date_time'
C:\boost_1_66_0\boost/date_time/filetime_functions.hpp(28): note: see declaration of 'boost::date_time'
src\mongo\util\time_support.cpp(936): error C3861: 'file_time_to_microseconds': identifier not found
scons: *** [build\win32\64\dbg_on\mongo\util\time_support.obj] Error 2
scons: building terminated because of errors.

【问题讨论】:

  • 以下答案是正确的,但好消息是我们正在努力修复它。请参阅下面的评论。

标签: c++ mongodb boost boost-date-time


【解决方案1】:

TL; DR - 你不能指望选择任意或当前版本的库并用它构建 MongoDB;他们在他们的 repo 中快照了他们的依赖关系,除了这些之外,没有任何关于构建版本的承诺。


MongoDB 在src/thirdparty directory 中有其依赖项的快照。快照的 boost 版本是 1.60,即released in 2015。可以看到,在那个版本的 boost 中,boost/date_time/filetime_functions.hpp 中定义了一个 winapi 命名空间。

但是,您正在尝试针对 boost 1.66(即released in December 2017)进行构建。发行说明提到了对 date_time 的更改:

日期时间:

  • 该库已转换为使用 Boost.WinAPI 作为 Windows SDK 的抽象层。

  • 修复了在从日期中添加或减去多年时可能导致错误结果的整数溢出(请参阅此处)。

该版本的 filetime_functions 在 date_time 中没有这个命名空间,current 1.67 snapshot of filetime_functions.hpp 也没有。

查看git blame log for src/mongo/util/time_support.cpp,看起来提到date_time::winapi 的mongo 代码是在3 年前添加的(在此winapi 重构之前),此后一直没有改变。

【讨论】:

  • 我们实际上正在升级我们的供应商提升依赖项并遇到了这个问题。我们会尽快修复它。
  • @FlorianWinter - 是的,MongoDB 4.2 已升级到 boost 1.70。
【解决方案2】:

如果您绝望了,并且您仍在使用报废的旧版 MongoDB 驱动程序(您不应该这样做!)并且此时无法更新您的所有代码(您最终必须这样做!),并且你需要一个快速补丁,然后你可以将以下代码(取自Boost 1.53.0)插入time_support.cpp

namespace boost {
  namespace date_time {
    namespace winapi {
    /*!
     * The function converts file_time into number of microseconds elapsed since 1970-Jan-01
     *
     * \note Only dates after 1970-Jan-01 are supported. Dates before will be wrapped.
     *
     * \note The function is templated on the FILETIME type, so that
     *       it can be used with both native FILETIME and the ad-hoc
     *       boost::date_time::winapi::file_time type.
     */
    template< typename FileTimeT >
    inline boost::uint64_t file_time_to_microseconds(FileTimeT const& ft)
    {
        /* shift is difference between 1970-Jan-01 & 1601-Jan-01
        * in 100-nanosecond intervals */
        const uint64_t shift = 116444736000000000ULL; // (27111902 << 32) + 3577643008

        union {
            FileTimeT as_file_time;
            uint64_t as_integer; // 100-nanos since 1601-Jan-01
        } caster;
        caster.as_file_time = ft;

        caster.as_integer -= shift; // filetime is now 100-nanos since 1970-Jan-01
        return (caster.as_integer / 10); // truncate to microseconds
    }
    }
  }
}

这将定义缺失的函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多