C++ boost::生成MongoDB时出现日期\时间错误:winapi不是成员
在使用SCons和boost构建MongoDB时,我遇到了一些错误。这是我的命令行: C:\mongo cxx驱动程序>Scons--prefix=$HOME/mongo客户端库--cpppath=C:\boost\u 1\u 66\u 0--libpath=C:\boost\u 1\u 66\u 0\stage64\lib--dbg=on--64安装 以下是我收到的错误消息:C++ boost::生成MongoDB时出现日期\时间错误:winapi不是成员,c++,mongodb,boost,boost-date-time,C++,Mongodb,Boost,Boost Date Time,在使用SCons和boost构建MongoDB时,我遇到了一些错误。这是我的命令行: C:\mongo cxx驱动程序>Scons--prefix=$HOME/mongo客户端库--cpppath=C:\boost\u 1\u 66\u 0--libpath=C:\boost\u 1\u 66\u 0\stage64\lib--dbg=on--64安装 以下是我收到的错误消息: src\mongo\util\time_support.cpp(904): error C2039: 'winapi'
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.
TL;DR-您不能期望选择任意或当前版本的库并使用它构建MongoDB;他们在他们的repo中快照他们的依赖关系,除了这些版本之外,没有关于构建版本的承诺
MongoDB在中有其依赖项的快照。在那里拍摄的boost Snapshot版本是1.60,这是一个新版本。您可以看到,在该版本的boost中,有一个定义在中的
winapi
名称空间
然而,您正试图针对boost 1.66进行构建,而boost 1.66是。发行说明中提到了对日期和时间的更改:
日期时间:
- 该库已转换为使用Boost.WinAPI作为Windows SDK的抽象层
- 修正了一个整数溢出,当从一个日期加上或减去许多年时,可能会导致不正确的结果(请参见此处)
看看,这看起来像是有问题的mongo代码提到的
date\u time::winapi
是3年前添加的(在这次winapi重构之前),并且从那时起就没有改变过。如果您非常绝望,并且仍然在使用生命终结的遗留MongoDB驱动程序(您不应该这么做!),此时无法更新所有代码(最终你必须这么做!),并且你需要一个快速补丁,然后你可以将以下代码(取自)插入time\u 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
}
}
}
}
namespace boost{
名称空间日期时间{
名称空间winapi{
/*!
*该函数将文件时间转换为自1970-01年1月以来经过的微秒数
*
*\注意:仅支持1970年1月1日之后的日期。将包装1970年1月1日之前的日期。
*
*\注意,函数是在FILETIME类型上模板化的,因此
*它既可以用于本机文件时间,也可以用于临时文件时间
*boost::日期\时间::winapi::文件\时间类型。
*/
模板
内联boost::uint64文件时间到微秒(文件时间常数和英尺)
{
/*1970-01年1月和1601-01年1月之间的班次差异
*以100纳秒的间隔*/
常数uint64\u t shift=1164444736000000000ull;//(27111902)实际上,我们正在升级我们的供应商boost依赖项,遇到了这个问题。我们很快就会解决它。@FlorianWinter-是的,MongoDB 4.2已经升级到boost 1.70。下面的答案是正确的,但好消息是我们正在解决它。请参阅下面我的评论。