【问题标题】:Compile error in boost header file. Fails on Centos 7, compiles on Ubuntu 16.04boost头文件中的编译错误。在 Centos 7 上失败,在 Ubuntu 16.04 上编译
【发布时间】: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 版本以最小化变量。任何帮助是极大的赞赏。谢谢。

【问题讨论】:

    标签: c++ ubuntu boost centos7


    【解决方案1】:

    根据错误消息,我的猜测(仅此而已,猜测)是您在某个地方:

    #define CR 13u
    

    这会导致编译错误。

    【讨论】:

    • 太棒了。就是这样!我包含了另一个定义 CR 的第 3 方头文件。我检查了 boost/chrono/duration.hpp 的 Ubuntu 版本,CR 变量被重命名为 CRRRRR。我猜他们遇到了类似的问题并修复了。看起来 centos 版本的 boost 仍然存在问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 2016-10-26
    • 2015-11-21
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    相关资源
    最近更新 更多