c++ -std=c++11 -stdlib=libc++ geben Fehler auf osx lion

Diese soll eine doppelte Frage. Aber ich habe gegoogelt sehr viel und habe nicht gefunden, ein Treffer der das behebt mein Problem.

Ich versuche, einen c++11-standard-feature bei osx lion und es funktioniert nicht. Ich glaube, diese Funktion wird als Liste Initialisierungen. nach http://clang.llvm.org/cxx_status.html Dieses feature wurde in clang 3.1, das ist die version, die ich verwende.

Unten ist die shell-o/p erklären meine einfachen test. Kann mir jemand sagen was ich falsch mache? Bin ich zu vergessen eine Flagge?

Ist der compiler:

:tmp$ c++ --version
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
:tmp$ which c++
/usr/bin/c++
:tmp$ ls -alt /usr/bin/c++
lrwxr-xr-x  1 root  wheel  7 Jul 12 13:17 /usr/bin/c++ -> clang++

OS ist

:tmp$ uname -a
Darwin .local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64

Die test-Datei ist

:tmp$ cat test.cpp
#include <vector>

int main(){
  std::vector<int> vec1 {1,2,3};
  std::vector<int> vec2={1,2,3};
}

Den compiler-output ist

:tmp$ c++ -std=c++11 test.cpp
 test.cpp:4:20: error: non-aggregate type 'std::vector<int>' cannot be
      initialized with an initializer list
  std::vector<int> vec1 {1,2,3};
                   ^    ~~~~~~~
test.cpp:5:20: error: non-aggregate type 'std::vector<int>' cannot be
      initialized with an initializer list
  std::vector<int> vec2={1,2,3};
                   ^    ~~~~~~~
2 errors generated.

Ok ich wollte nicht zu bekommen, weil es das folgende nimmt sich viel zu format richtig auf stackoverflow. Aber das hinzufügen -stdlib=c++ schafft noch mehr Probleme. Jetzt bekomme ich 14 Fehler.

:tmp$ c++ -std=c++11 -stdlib=libc++ test.cpp 
In file included from test.cpp:1:
In file included from /usr/bin/../lib/c++/v1/vector:261:
In file included from /usr/bin/../lib/c++/v1/__bit_reference:15:
In file included from /usr/bin/../lib/c++/v1/algorithm:591:
/usr/bin/../lib/c++/v1/type_traits:737:2: error: #error is_base_of not
      implemented.
#error is_base_of not implemented.
 ^
/usr/bin/../lib/c++/v1/type_traits:1700:13: error: use of undeclared identifier
      'is_base_of'
            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
            ^
/usr/bin/../lib/c++/v1/type_traits:1700:24: error: '_Class' does not refer to a
      value
            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
                   ^
/usr/bin/../lib/c++/v1/type_traits:1697:28: note: declared here
template <class _Rp, class _Class, class _Tp>
                           ^
/usr/bin/../lib/c++/v1/type_traits:1700:62: error: expected class name
            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
                                                             ^
In file included from test.cpp:1:
In file included from /usr/bin/../lib/c++/v1/vector:261:
In file included from /usr/bin/../lib/c++/v1/__bit_reference:15:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In file included from /usr/bin/../lib/c++/v1/memory:590:
In file included from /usr/bin/../lib/c++/v1/typeinfo:61:
/usr/bin/../lib/c++/v1/exception:194:20: error: use of undeclared identifier
      'is_base_of'
                  !is_base_of<nested_exception, typename ...
               ^
/usr/bin/../lib/c++/v1/exception:194:31: error: 'nested_exception' does not
      refer to a value
                  !is_base_of<nested_exception, typename ...
                              ^
/usr/bin/../lib/c++/v1/exception:166:29: note: declared here
class _LIBCPP_EXCEPTION_ABI nested_exception
                            ^
/usr/bin/../lib/c++/v1/exception:194:81: error: parameter declarator cannot be
      qualified
  ...typename remove_reference<_Tp>::type>::value
                                   ~~^
/usr/bin/../lib/c++/v1/exception:194:85: error: expected ')'
  ...typename remove_reference<_Tp>::type>::value
                                         ^
/usr/bin/../lib/c++/v1/exception:192:18: note: to match this '('
throw_with_nested(_Tp&& __t, typename enable_if<
                 ^
/usr/bin/../lib/c++/v1/exception:213:19: error: use of undeclared identifier
      'is_base_of'
                  is_base_of<nested_exception, typename ...
              ^
/usr/bin/../lib/c++/v1/exception:213:30: error: 'nested_exception' does not
      refer to a value
                  is_base_of<nested_exception, typename ...
                         ^
/usr/bin/../lib/c++/v1/exception:166:29: note: declared here
class _LIBCPP_EXCEPTION_ABI nested_exception
                            ^
/usr/bin/../lib/c++/v1/exception:213:80: error: parameter declarator cannot be
      qualified
  ...typename remove_reference<_Tp>::type>::value
                                   ~~^
/usr/bin/../lib/c++/v1/exception:213:84: error: expected ')'
  ...typename remove_reference<_Tp>::type>::value
                                         ^
/usr/bin/../lib/c++/v1/exception:211:18: note: to match this '('
throw_with_nested(_Tp&& __t, typename enable_if<
                 ^
test.cpp:4:20: error: non-aggregate type 'std::vector<int>' cannot be
      initialized with an initializer list
  std::vector<int> vec1 {1,2,3};
                   ^    ~~~~~~~
test.cpp:5:20: error: non-aggregate type 'std::vector<int>' cannot be
      initialized with an initializer list
  std::vector<int> vec2={1,2,3};
                   ^    ~~~~~~~
14 errors generated.
  • möglich, Duplikat der Wie bekomme ich die neuen C++ threading-Unterstützung in Mac OS X mit clang? und siehe auch stackoverflow.com/a/14150421/981959 für eine ausführliche Erklärung
  • Der zweite Fehler scheint ein bug in der libc++, es nicht implementieren die Funktionen, die Sie verwenden. Probieren Sie ein Upgrade auf LLVM/Clang/libc++ 3.2
  • Und zum formatieren einer ganzen block richtig fügen Sie einfach es in, und wählen Sie dann den ganzen block und drücken Sie Strg + K (oder die {} - Symbol über der textbox)
  • Ich habe die neuste version von XCode für Lion. Bedeutet das XCode auf Lion ist gebrochen? Ich will nicht, um ein upgrade für mein OS oder gehen Sie entlang der darwin-ports route.
  • Vielen Dank für die block-Kommentar-Tipp auch.
  • Beachten Sie, dass "Apple clang version 3.1" ist nicht das gleiche wie "LLVM-Clang 3.1". Auf Mountain Lion, die Sie erhalten würden "Apple clang version 4.0", auch "basierend auf LLVM 3.1".

InformationsquelleAutor Spundun | 2013-01-10
Schreibe einen Kommentar