2012-05-02 22 views
5

MacPorts tarafından yüklenen clang kullanarak C++ 11'de listelerin başlatılması özelliğini deniyorum. Bu basit bir kod derlerken:MacPorts Clang 3.1 Standart Kütüphane kurulumu yüklenmemiş mi?

stephen-chus-mac-pro:~ stephenchu$ clang -std=c++0x -c text.cxx -I/opt/local/include -v 
clang version 3.1 (trunk 154872) 
Target: x86_64-apple-darwin10.8.0 
Thread model: posix 
"/opt/local/libexec/llvm-3.1/bin/clang" -cc1 -triple x86_64-apple-macosx10.6.0 -emit-obj -mrelax-all -disable-free -main-file-name text.cxx -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 127.2 -v -coverage-file text.o -resource-dir /opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1 -I /opt/local/include -fmodule-cache-path /var/folders/UL/ULMxdJJtEQuI+WuToNAFpk+++TI/-Tmp-/clang-module-cache -std=c++0x -fdeprecated-macro -fdebug-compilation-dir /Users/stephenchu -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o text.o -x c++ text.cxx 
clang -cc1 version 3.1 based upon LLVM 3.1svn default target x86_64-apple-darwin10.8.0 
#include "..." search starts here: 
#include <...> search starts here: 
/opt/local/include 
/usr/include/c++/4.2.1 
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64 
/usr/include/c++/4.2.1/backward 
/usr/include/c++/4.0.0 
/usr/include/c++/4.0.0/i686-apple-darwin8 
/usr/include/c++/4.0.0/backward 
/usr/local/include 
/opt/local/libexec/llvm-3.1/bin/../lib/clang/3.1/include 
/usr/include 
/System/Library/Frameworks (framework directory) 
/Library/Frameworks (framework directory) 
End of search list. 
text.cxx:5:19: error: no matching constructor for initialization of 
     'std::vector<int>' 
     std::vector<int> a {1, 3, 5}; 
         ^~~~~~~~~~ 
/usr/include/c++/4.2.1/bits/stl_vector.h:255:9: note: candidate constructor 
     [with _InputIterator = int] not viable: no known conversion from 'int' to 
     'const allocator_type' (aka 'const std::allocator<int>') for 3rd argument; 
     vector(_InputIterator __first, _InputIterator __last, 
     ^
/usr/include/c++/4.2.1/bits/stl_vector.h:213:7: note: candidate constructor not 
     viable: no known conversion from 'int' to 'const allocator_type' (aka 
     'const std::allocator<int>') for 3rd argument; 
     vector(size_type __n, const value_type& __value = value_type(), 
    ^
/usr/include/c++/4.2.1/bits/stl_vector.h:201:7: note: candidate constructor not 
     viable: requires at most 1 argument, but 3 were provided 
     vector(const allocator_type& __a = allocator_type()) 
    ^
/usr/include/c++/4.2.1/bits/stl_vector.h:231:7: note: candidate constructor not 
     viable: requires 1 argument, but 3 were provided 
     vector(const vector& __x) 
    ^
1 error generated. 

sistem gcc (4.2) başlıkları içerecek şekilde görünüyor:

#include <vector> 

int main() 
{ 
    std::vector<int> a {1, 3, 5}; 
    return 0; 
} 

bu hata var. Ve ben herhangi bir argo belirli üstbilgileri bulamıyorum. Bunun çalışması için MacPorts'tan hangi paketi yüklemeliyim? Ya da clang'ın libC++'sini yüklemem ve kurmam gerekiyor mu?

+1

[Gerçekten "C++ standart kitaplığı" nı kastettiğinizi umuyorum.) (Http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all- yaklaşık/5205571 # 5205571) – Griwes

+0

@Griwes yes. Bunu yansıtmak için soruyu düzenledim. Yanlış dönem için özür dilerim. –

cevap

3

Önce Sonra güncellenmiş başlıkları gerekebilir '-stdlib = libC++'

standart kütüphane ayarlamak gerekir. En yeni libC++ üstbilgileri, OS X 10.7 ve üstü ile yüklenen libC++ libs ile çalışır.

Macports'ın libC++ olduğunu bilmiyorum, ancak ihtiyacınız olan tek şey başlıkları olduğu için bunları indirebilmeli ve clang'ın yüklü olduğu yere bitişik ekleme dizinine bırakabilmelisiniz.

+0

Teşekkürler. Bunu, OSC 10.6 ve Xcode 4.2 ile libC++ içermediğinden (bunu bulabildiğimden) bahsetmeyi unuttum. LibC++ başlıklarını kuracağım ve göreceğim. –

+0

Dahili ve yerleşik libC++ kaynağından ve şimdi çalışıyor. Teşekkürler. –

İlgili konular