使用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.
答案 0 :(得分:1)
TL; DR -您不能指望选择一个任意或当前版本的库并以此构建MongoDB;他们在存储库中快照了他们的依赖关系,除了这些版本之外,没有其他关于构建版本的承诺。
MongoDB在src/thirdparty directory中具有其依赖项的快照。快照的boost版本为1.60,即released in 2015。您可以看到在该版本的boost中,在boost/date_time/filetime_functions.hpp
中定义了一个winapi
命名空间。
但是,您正在尝试以1.66(即released in December 2017)为基础进行构建。发行说明中提到了对date_time的更改:
DateTime:
该库已转换为使用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重构之前)添加的,此后一直没有改变。
答案 1 :(得分:0)
如果您绝望了,并且仍在使用寿命终止的旧版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
}
}
}
}
这将定义缺少的功能。