Antonio SEO
Antonio SEO

Reputation: 497

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

While building MongoDB with SCons and boost, I'm getting errors. Here's my command line:

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

Here are the error messages I'm getting:

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.

Upvotes: 1

Views: 361

Answers (2)

Florian Winter
Florian Winter

Reputation: 5319

If you are desperate, and you are still using the end-of-life legacy MongoDB driver (which you shouldn't!) and cannot update all your code at this time (which you have to, eventually!), and you need a quick patch, then you can insert the following code (taken from Boost 1.53.0) into 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
    }
    }
  }
}

This will define the missing function.

Upvotes: 0

TL; DR - You can't expect to pick an arbitrary or current version of a library and build MongoDB with it; they snapshot their dependencies in their repo and there's no promises about building with versions besides those.


MongoDB has snapshots of its dependencies in the 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.

However, you're trying to build against boost 1.66, which was released in December 2017. The release notes mention changes to 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).

That version of filetime_functions does not have this namespace inside of date_time, nor does the current 1.67 snapshot of filetime_functions.hpp.

Looking at the git blame log for src/mongo/util/time_support.cpp, it looks like the mongo code in question mentioning date_time::winapi was added 3 years ago (before this winapi refactoring) and hasn't changed since.

Upvotes: 1

Related Questions