2012-08-07 19 views
16

मैं सिर्फ बजना के साथ प्रयोग करना शुरू कर दिया और निम्नलिखित नमूना कार्यक्रम संकलन करने की कोशिश की है:clang 3.1 unique_ptr नहीं देख सकता है?

#include <memory> 
#include <iostream> 

int main() 
{ 
    std::unique_ptr<unsigned> u(new unsigned(10)); 
    std::cout << *u << std::endl; 
    return 0; 
} 

जब मैं संकलन मैं निम्नलिखित त्रुटियाँ मिलती है:

$ clang++ helloworld.cpp 
helloworld.cpp:6:10: error: no member named 'unique_ptr' in namespace 'std' 
    std::unique_ptr<unsigned> u(new unsigned(10)); 
    ~~~~~^ 
helloworld.cpp:6:29: error: expected '(' for function-style cast or type construction 
    std::unique_ptr<unsigned> u(new unsigned(10)); 
        ~~~~~~~~^ 
helloworld.cpp:6:31: error: use of undeclared identifier 'u' 
    std::unique_ptr<unsigned> u(new unsigned(10)); 
          ^
helloworld.cpp:7:19: error: use of undeclared identifier 'u' 
    std::cout << *u << std::endl; 
       ^
4 errors generated. 

मैं मैक पर बजना 3.1 उपयोग कर रहा हूँ ओएस एक्स:

$ clang++ --version 
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn) 
Target: x86_64-apple-darwin11.4.0 
Thread model: posix 

कोई विचार क्यों संकलित नहीं करेगा?

उत्तर

27

मैं

clang++ test.cpp -std=c++11 -stdlib=libc++ 
+10

+1 इस विशेष उदाहरण संकलित कर देगा का उपयोग करके संकलित करने के लिए मिल गया '-std = C++ 11' के बिना। हालांकि सी ++ 03 भाषा मोड में 'unique_ptr' के लिए समर्थन कमजोर है, इसलिए मैं' -std = C++ 11' की अनुशंसा करता हूं। '-stdlib = libC++' libC++ (http://libcxx.llvm.org) चुनता है। इस ध्वज के बिना clcc डिफ़ॉल्ट gcc-4.2 से libstdC++ का उपयोग करने के लिए डिफ़ॉल्ट है, जिसमें कोई C++ 11 लाइब्रेरी सुविधाएं नहीं हैं (tr1 नामस्थान में सबसेट से अलग)। –

+0

हावर्ड किस समस्या के बारे में बात कर रहा है, एलएलवीएम/क्लैंग के तहत संकलित करते समय [4stackoverflow.com/q/31655462) पर चार टेस्ट केस देखें [नामस्थान 'std' में 'unique_ptr' नाम का कोई प्रकार नहीं। – jww

संबंधित मुद्दे