boost::xtime 没有名为 'is_pos_infinity' 的成员

boost::xtime has no member named 'is_pos_infinity'

我的任务是移植一个遗留软件,客户决定在此过程中将 Boost 从 1.34 更新到 1.75。

不幸的是,我在编译时遇到了这个问题:

/usr/include/boost/thread/pthread/recursive_mutex.hpp: In instantiation of ‘bool boost::recursive_timed_mutex::timed_lock(const TimeDuration&) [with TimeDuration = boost::xtime]’:
/usr/include/boost/thread/lock_types.hpp:403:30:   required from ‘bool boost::unique_lock<Mutex>::timed_lock(const boost::xtime&) [with Mutex = boost::recursive_timed_mutex]’
/usr/include/boost/thread/lock_types.hpp:146:17:   required from ‘boost::unique_lock<Mutex>::unique_lock(Mutex&, const TimeDuration&) [with TimeDuration = boost::xtime; Mutex = boost::recursive_timed_mutex]’
{project source file}.hpp:206:118:   required from here
/usr/include/boost/thread/pthread/recursive_mutex.hpp:244:31: error: ‘const struct boost::xtime’ has no member named ‘is_pos_infinity’
  244 |             if (relative_time.is_pos_infinity())
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/boost/thread/pthread/recursive_mutex.hpp:249:31: error: ‘const struct boost::xtime’ has no member named ‘is_special’
  249 |             if (relative_time.is_special())
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/boost/thread/pthread/recursive_mutex.hpp:253:39: error: no matching function for call to ‘boost::detail::platform_duration::platform_duration(const boost::xtime&)’
  253 |             detail::platform_duration d(relative_time);
      |                                       ^

这里发生了什么让 Boost 对自己不满意,我该如何解决?

我认为这与我们之前在此处看到的 third-party headers 冲突:

"xtime: ambiguous symbol" error, when including <boost/asio.hpp>

在这种情况下,对包含的内容重新排序就可以了。如果这在您的情况下不起作用,您应该找出应该归咎于哪个库(通常是使用(宏)定义污染全局命名空间的库)。

然后您可以将缺陷报告给各自的维护者。

在我的特殊情况下,我能够找到根本原因并修复它。

我觉得最新的文档在确定预期输入变量的类型方面的布局很奇怪,但根据 Boost v1.75 doc, m.timed_lock(t) expects a type of boost::system_time, yet was still being fed a boost::xtime, which was what it expected back in Boost v1.34.

我们的源代码中一些计算输入 m.timed_lock(t) 的等待时间的地方提供了 boost::xtime,我只需要更改它们以提供 boost::system_time