这是 boost 库中的错误吗

Posted

技术标签:

【中文标题】这是 boost 库中的错误吗【英文标题】:Is this a bug in the boost library 【发布时间】:2017-01-21 09:57:20 【问题描述】:

我正在使用 autotools 编译一个项目,并在版本 gcc version 5.3.1 和 boost 版本 1_63 中使用 g++。在aclocalautoconfautoheader、automake --add-missing 之后,我用一些选项运行了configure,这些选项成功并构建了一个 Makefile。运行 make 失败并给我错误(摘录):

In file included from /usr/local/include/boost/ratio/ratio.hpp:46:0,
             from /usr/local/include/boost/chrono/duration.hpp:41,
             from /usr/local/include/boost/chrono/time_point.hpp:33,
             from /usr/local/include/boost/thread/lock_types.hpp:22,
             from /usr/local/include/boost/thread/pthread/mutex.hpp:16,
             from /usr/local/include/boost/thread/mutex.hpp:16,
             from src/cosupport-initializer/cpp/BasicInitializer.cpp:39:
/usr/local/include/boost/integer_traits.hpp:83:46: error: 'CHAR_MIN' was not declared in this scope
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
                                          ^
/usr/local/include/boost/integer_traits.hpp:83:56: error: 'CHAR_MAX' was not declared in this scope
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
                                                    ^
/usr/local/include/boost/integer_traits.hpp:83:64: error: template argument 2 is invalid
public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
                                                            ^
/usr/local/include/boost/integer_traits.hpp:83:64: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:89:53: error: 'SCHAR_MIN' was not declared in this scope
public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
                                                 ^
/usr/local/include/boost/integer_traits.hpp:89:64: error: 'SCHAR_MAX' was not declared in this scope
 public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
                                                            ^
/usr/local/include/boost/integer_traits.hpp:89:73: error: template argument 2 is invalid
public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX>
                                                                     ^
/usr/local/include/boost/integer_traits.hpp:89:73: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:95:58: error: 'UCHAR_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
                                                      ^
/usr/local/include/boost/integer_traits.hpp:95:67: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX>
                                                               ^
/usr/local/include/boost/integer_traits.hpp:131:47: error: 'SHRT_MIN' was not declared in this scope
public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
                                           ^
/usr/local/include/boost/integer_traits.hpp:131:57: error: 'SHRT_MAX' was not declared in this scope
public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
                                                     ^
/usr/local/include/boost/integer_traits.hpp:131:65: error: template argument 2 is invalid
public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX>
                                                             ^
/usr/local/include/boost/integer_traits.hpp:131:65: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:137:59: error: 'USHRT_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned short, 0, USHRT_MAX>
                                                       ^
/usr/local/include/boost/integer_traits.hpp:137:68: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned short, 0, USHRT_MAX>
                                                                ^
/usr/local/include/boost/integer_traits.hpp:143:45: error: 'INT_MIN' was not declared in this scope
public detail::integer_traits_base<int, INT_MIN, INT_MAX>
                                         ^
/usr/local/include/boost/integer_traits.hpp:143:54: error: 'INT_MAX' was not declared in this scope
public detail::integer_traits_base<int, INT_MIN, INT_MAX>
                                                  ^
/usr/local/include/boost/integer_traits.hpp:143:61: error: template argument 2 is invalid
public detail::integer_traits_base<int, INT_MIN, INT_MAX>
                                                         ^
/usr/local/include/boost/integer_traits.hpp:143:61: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:149:57: error: 'UINT_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned int, 0, UINT_MAX>
                                                     ^
/usr/local/include/boost/integer_traits.hpp:149:65: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned int, 0, UINT_MAX>
                                                             ^
/usr/local/include/boost/integer_traits.hpp:155:46: error: 'LONG_MIN' was not declared in this scope
public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
                                          ^
/usr/local/include/boost/integer_traits.hpp:155:56: error: 'LONG_MAX' was not declared in this scope
public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
                                                    ^
/usr/local/include/boost/integer_traits.hpp:155:64: error: template argument 2 is invalid
public detail::integer_traits_base<long, LONG_MIN, LONG_MAX>
                                                            ^
/usr/local/include/boost/integer_traits.hpp:155:64: error: template argument 3 is invalid
/usr/local/include/boost/integer_traits.hpp:161:58: error: 'ULONG_MAX' was not declared in this scope
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
                                                      ^
/usr/local/include/boost/integer_traits.hpp:161:67: error: template argument 3 is invalid
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>

这意味着例如在第 83 行的/usr/local/include/boost/integer_traits.hpp 中,构造函数初始化失败:

template<>
class integer_traits<char>
  : public std::numeric_limits<char>,
    public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX>
 ;

这意味着在文件/usr/local/include/boost/integer_traits.hpp 和包含在其中的标题中,没有CHAR_MIN 的定义。所以这是boost中的一个错误?或者我在这里错过了什么?

更新

相关代码摘录。搬家前:

#include <CoSupport/compatibility-glue/nullptr.h>
#include <CoSupport/Initializer/BasicInitializer.hpp>
#include <boost/thread/mutex.hpp>
#include <cassert>

namespace CoSupport 
...

搬家后:

#include <boost/thread/mutex.hpp>
#include <CoSupport/compatibility-glue/nullptr.h>
#include <CoSupport/Initializer/BasicInitializer.hpp>
#include <cassert>

namespace CoSupport 
...

【问题讨论】:

向我们展示实际的源代码。如果将 #include 从第 39 行移到第 1 行会发生什么? 还是同样的错误。我把它放在第一行(在 cmets 之后):from src/cosupport-initializer/cpp/BasicInitializer.cpp:35: /usr/local/include/boost/integer_traits.hpp:83:46: error: 'CHAR_MIN' was not declared in this scope public detail::integer_traits_base&lt;char, CHAR_MIN, CHAR_MAX&gt; 那么这看起来像一个错误,因为 Boost 违反了每个标头应该包含它需要的所有其他标头的原则。你之前#include &lt;limits.h&gt;的时候,有用吗? 但是等等,boost.org/doc/libs/1_59_0/boost/limits.hpp 已经包含了&lt;limits&gt;,所以肯定有其他问题。检查是否定义了任何与现有头文件冲突的头文件。 @RolandIllig 定义 CHAR_MIN,MAX 的不是&lt;limits&gt;,而是&lt;climits&gt;。似乎是 boost 中的一个错误。 【参考方案1】:

这意味着在文件/usr/local/include/boost/integer_traits.hpp 和包含在其中的标题中,没有CHAR_MIN 的定义

应该是这样 - CHAR_MIN&lt;climits&gt; 中定义。

所以这是 boost 中的一个错误?或者我在这里错过了什么?

有 99% 的把握,这不是 boost 中的错误。您可能有一些您自己的包含文件,在您的项目的包含目录中,掩蔽climitslimits.h,或者可能是interger_traits.hpp 包含的另一个文件,它本身包含climitslimits.h

【讨论】:

以上是关于这是 boost 库中的错误吗的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 boost 库中的 integer_sort?

哪种算法需要“访问者”(boost 库中的术语)?

在 Boost Property 树库中,我如何以自定义方式处理文件未找到错误(C++)

C++11实现的Boost库中的Any类

boost库中的 program_options

*.pyd 库中的 C++ Boost Python 方法不起作用