[英]compile error for boost::date_time::days_until_weekday
[英]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安裝
以下是我收到的錯誤消息:
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 在src/thirdparty 目錄中有其依賴項的快照。 那里快照的 boost 版本是 1.60,它是2015年發布的。 您可以看到在那個版本的 boost 中,在boost/date_time/filetime_functions.hpp
定義了一個winapi
命名空間。
但是,您正在嘗試針對2017 年 12 月發布的boost 1.66 進行構建。 發行說明提到了 date_time 的變化:
約會時間:
該庫已轉換為使用 Boost.WinAPI 作為 Windows SDK 的抽象層。
修復了在從日期中添加或減去多年時可能導致錯誤結果的積分溢出(請參見此處)。
那個版本的 filetime_functions 在 date_time 中沒有這個命名空間,filetime_functions.hpp的當前 1.67 快照也沒有。
查看 src/mongo/util/time_support.cpp的git blame 日志,看起來有問題的 mongo 代碼提到date_time::winapi
是在 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
}
}
}
}
這將定義缺失的函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.