2013-01-13 37 views
2

當試圖編譯鐺+的libC++(C++ 11模式)這一條線:升壓/ thread.hpp失敗 '鐺++ -std = C++ 11 -stdlib = libc的++'

#include <boost/thread.hpp> 

鐺發出以下錯誤:

 
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 

回答

3

隨着馬克思的提示,我找到了一個解決方法。在這種情況下定義BOOST_NO_CXX11_NUMERIC_LIMITS有幫助。所以它似乎是libC++的不完整。

根據Howard Hinnant的說法,這是一個libC++的bug,已經固定在主幹上。但是,當Apple可以將修復發佈到Xcode中時,還沒有任何信息。我將標記現在回答的問題。

編輯:該問題已修復在Apple LLVM 4.2版(clang-425.0.28)(基於LLVM 3.2svn)中。我目前的Xcode版本是4.6.3。

+1

在這方面已修復了提示主幹libC++(http://libcxx.llvm.org)。 –

+0

很高興知道。謝謝,霍華德。你知道蘋果什麼時候將解決方案發布到Xcode更新中嗎? –

+0

對不起,我不知道。 –

2

我使用boost在Xcode 4.3,並使用隨機TR1,最前一頁也建立自己的錯誤,但我定義的#define BOOST_HAS_TR1_RANDOM 1的#include之前,成功打造。你可以嘗試類似的方式,手動指出構建器有它自己的tr1實現。這可能是構建boost腳本的bug。

+0

感謝您的提示。在我的情況下,'BOOST_NO_CXX11_NUMERIC_LIMITS'有幫助。但是,這與增強建設無關。使用boost頭文件會導致編譯失敗。 –