boost / thread.hpp失败,'clang ++ -std = c ++ 11 -stdlib = libc ++'

时间:2013-01-13 02:38:28

标签: c++ boost c++11 clang libc++

尝试使用clang + libc ++(C ++ 11模式)编译这一行时:

#include <boost/thread.hpp>

clang会发出以下错误:

In file included from test.cpp:1:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33:
/Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:353:49: error: 
  constexpr function never produces a constant expression
    static BOOST_CHRONO_LIB_CONSTEXPR float lowest() ...
                        ^
/Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:355:21: note: 
  non-constexpr function 'max' cannot be used in a constant expression
    return -(std::numeric_limits::max) ();
        ^
/usr/bin/../lib/c++/v1/limits:443:43: note: declared here
_LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ...
                      ^
In file included from test.cpp:1:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33:
/Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:361:50: error: 
  constexpr function never produces a constant expression
    static BOOST_CHRONO_LIB_CONSTEXPR double lowest() ...
                         ^
/Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:363:21: note: 
  non-constexpr function 'max' cannot be used in a constant expression
    return -(std::numeric_limits::max) ();
        ^
/usr/bin/../lib/c++/v1/limits:443:43: note: declared here
_LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ...
                      ^
In file included from test.cpp:1:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread.hpp:13:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/thread.hpp:17:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/pthread/thread_data.hpp:11:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/thread/locks.hpp:18:
In file included from /Users/yongwei/Programming/boost_1_52_0/boost/chrono/time_point.hpp:33:
/Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:369:55: error: 
  constexpr function never produces a constant expression
    static BOOST_CHRONO_LIB_CONSTEXPR long double lowest() ...
                          ^
/Users/yongwei/Programming/boost_1_52_0/boost/chrono/duration.hpp:371:21: note: 
  non-constexpr function 'max' cannot be used in a constant expression
    return -(std::numeric_limits::max)();
        ^
/usr/bin/../lib/c++/v1/limits:443:43: note: declared here
_LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return ...
                      ^
3 errors generated.

我认为这是libc ++中的一个错误,因为C ++ 11确实要求这些函数为constexpr

任何人遇到同样的问题,你能同意吗?你知道任何修复吗?

我的铿锵声版本是:

Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

2 个答案:

答案 0 :(得分:3)

马克思的暗示,我找到了一个解决方法。在这种情况下,定义BOOST_NO_CXX11_NUMERIC_LIMITS会有所帮助。所以它似乎是libc ++的不完整性。

根据Howard Hinnant的说法,这是一个libc ++的错误,已经在主干上修复了。但是,当Apple可以将修复程序发布到Xcode时,还没有任何信息。我现在将标记回答的问题。

编辑:Apple LLVM版本4.2(clang-425.0.28)(基于LLVM 3.2svn)修复了该问题。我目前的Xcode版本是4.6.3。

答案 1 :(得分:2)

我在xcode 4.3中使用boost,并使用tr1 random,fisrt也构建错误,但我在#include之前定义了#define BOOST_HAS_TR1_RANDOM 1并成功构建。您可以尝试类似的方式,手动指出构建器有自己的tr1实现。这可能是boost的构建脚本的错误。