【发布时间】:2018-02-21 02:04:41
【问题描述】:
我遇到了一个奇怪的编译问题。任何解决它的帮助将不胜感激。我正在将我的应用程序与 boost 库链接起来。我需要在 Centos 和 Ubuntu 上编译我的应用程序。在 Ubuntu 上一切正常,相同的代码在 Centos 7 上编译失败。错误的位置在 boost 中。不确定问题是否实际上是在 boost 中,或者是否有其他原因导致错误出现在 boost 中。我在搜索错误时遇到了这个link。但是,该问题适用于旧版本的 boost。我在下面列出了错误输出:
/usr/local/include/boost/chrono/duration.hpp: In function 'constexpr typename boost::enable_if<boost::mpl::and_<boost::is_convertible<Rep1, typename boost::common_type<Rep1, Rep2>::type>, boost::is_convertible<Rep2, typename boost::common_type<Rep1, Rep2>::type> >, boost::chrono::duration<typename boost::common_type<Rep1, Rep2>::type, Period> >::type boost::chrono::operator*(const boost::chrono::duration<Rep, Period>&, const Rep2&)':
In file included from /usr/local/include/boost/chrono/time_point.hpp:33:0,
from /usr/local/include/boost/thread/lock_types.hpp:22,
from /usr/local/include/boost/thread/lock_algorithms.hpp:11,
from /usr/local/include/boost/thread/locks.hpp:10,
...
/usr/local/include/boost/chrono/duration.hpp:575:34: error: type/value mismatch at argument 1 in template parameter list for 'template<class Rep, class Period> class boost::chrono::duration'
typedef duration<CR, Period> CD;
^
/usr/local/include/boost/chrono/duration.hpp:575:34: error: expected a type, got '13u'
/usr/local/include/boost/chrono/duration.hpp:575:38: error: invalid type in declaration before ';' token
typedef duration<CR, Period> CD;
来自/usr/local/include/boost/chrono/duration.hpp的对应代码:
// Duration *
template <class Rep1, class Period, class Rep2>
inline BOOST_CONSTEXPR
typename boost::enable_if <
mpl::and_ <
boost::is_convertible<Rep1, typename common_type<Rep1, Rep2>::type>,
boost::is_convertible<Rep2, typename common_type<Rep1, Rep2>::type>
>,
duration<typename common_type<Rep1, Rep2>::type, Period>
>::type
operator*(const duration<Rep1, Period>& d, const Rep2& s)
{
typedef typename common_type<Rep1, Rep2>::type CR;
typedef duration<CR, Period> CD;
return CD(CD(d).count()*static_cast<CR>(s));
}
我在 Centos7 上收到此错误。在 Ubuntu 上不会发生。
Centos 版本:
Boost:1.58.0,操作系统:Centos 7,C++:g++ 4.8.5
Ubuntu 版本:
Boost:1.58.0,操作系统:Ubuntu 16.04,C++:g++ 5.4.0
不确定 C++ 编译器的差异是否是问题所在。 Centos7 上 c++ 编译器的默认版本是 4.8.5。顺便说一句,CentOS7 上的默认 boost 版本是 1.53.2。我编译并安装了 boost 1.58.0 版本以最小化变量。任何帮助是极大的赞赏。谢谢。
【问题讨论】: