boost::date_time 构建时出错 MongoDB: winapi 不是成员

boost::date_time error while building MongoDB: winapi is not member

在使用 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 install

这是我收到的错误消息:

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\dbg_on\mongo\util\time_support.obj] Error 2
scons: building terminated because of errors.

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


MongoDB 在 src/thirdparty directory. The version of boost snapshotted there is 1.60, which was released in 2015. You can see that in that version of boost, there is a winapi namespace defined in boost/date_time/filetime_functions.hpp.

中有其依赖项的快照

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

的更改

DateTime:

  • The library has been converted to use Boost.WinAPI as the abstraction layer for Windows SDK.

  • Fixed an integral overflow that could cause incorrect results when adding or subtracting many years from a date (see here).

那个版本的 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 重构之前),此后一直没有改变。

如果您走投无路,并且仍在使用已停产的遗留 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
    }
    }
  }
}

这将定义缺失的函数。