Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++-std=c++;11-stdlib=libc++;在osx lion上给出错误_C++_Macos_Osx Lion_Llvm_Llvm 3.0 - Fatal编程技术网

C++ c++-std=c++;11-stdlib=libc++;在osx lion上给出错误

C++ c++-std=c++;11-stdlib=libc++;在osx lion上给出错误,c++,macos,osx-lion,llvm,llvm-3.0,C++,Macos,Osx Lion,Llvm,Llvm 3.0,这应该是一个重复的问题。但我在谷歌上搜索了不少,还没有找到一个能解决我问题的热门搜索 我试图在osx lion上使用c++11标准功能,但它不起作用。我相信这个特性叫做列表初始化器。据我所知,这个特性出现在我正在使用的Clang3.1版本中 下面是解释我的简单测试的shell o/p。谁能告诉我我做错了什么?我忘了带国旗了吗 编译器是: :tmp$ c++ --version Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based o

这应该是一个重复的问题。但我在谷歌上搜索了不少,还没有找到一个能解决我问题的热门搜索

我试图在osx lion上使用c++11标准功能,但它不起作用。我相信这个特性叫做列表初始化器。据我所知,这个特性出现在我正在使用的Clang3.1版本中

下面是解释我的简单测试的shell o/p。谁能告诉我我做错了什么?我忘了带国旗了吗

编译器是:

: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++
操作系统是

: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
测试文件是

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

int main(){
  std::vector<int> vec1 {1,2,3};
  std::vector<int> vec2={1,2,3};
}
:tmp$cat test.cpp
#包括
int main(){
std::向量vec1{1,2,3};
向量vec2={1,2,3};
}
编译器输出为

: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.
<代码>:TMP $C++ + STD= C++ 11 Test.CPP test.cpp:4:20:错误:无法创建非聚合类型“std::vector” 使用初始值设定项列表初始化 std::向量vec1{1,2,3}; ^ ~~~~~~~ test.cpp:5:20:错误:无法创建非聚合类型“std::vector” 使用初始值设定项列表初始化 向量vec2={1,2,3}; ^ ~~~~~~~ 产生2个错误。 好的,我不想去那里,因为下面要在stackoverflow上正确格式化需要很多时间。但是添加-stdlib=c++会产生更多的问题。现在我有14个错误

: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.
<代码>:TMP $C++ + STD= C++ 11 -STDLIB=LBC++TEST.CPP 在test.cpp中包含的文件中:1: 在/usr/bin/./lib/c++/v1/vector:261中包含的文件中: 在/usr/bin/./lib/c++/v1/u位的文件中,参考:15: 在/usr/bin/./lib/c++/v1/算法中包含的文件中:591: /usr/bin/。/lib/c++/v1/type_traits:737:2:error:#error是非的基础 执行。 #错误为未实现的\u base\u。 ^ /usr/bin/。/lib/c++/v1/type_traits:1700:13:错误:使用未声明的标识符 '是'的基础' 基本值是否为::value> ^ /usr/bin/。/lib/c++/v1/type_traits:1700:24:错误:“_Class”不引用 价值 基本值是否为::value> ^ /usr/bin/。/lib/c++/v1/type_traits:1697:28:注:此处声明 模板 ^ /usr/bin/。/lib/c++/v1/type_traits:1700:62:错误:应为类名 基本值是否为::value> ^ 在test.cpp中包含的文件中:1: 在/usr/bin/./lib/c++/v1/vector:261中包含的文件中: 在/usr/bin/./lib/c++/v1/u位的文件中,参考:15: 在/usr/bin/./lib/c++/v1/算法中包含的文件中:594: 在/usr/bin/./lib/c++/v1/内存中包含的文件中:590: 在/usr/bin/./lib/c++/v1/typeinfo:61中包含的文件中: /usr/bin/。/lib/c++/v1/异常:194:20:错误:使用未声明的标识符 '是'的基础' !_base_为::value吗 ^ /usr/bin/。/lib/c++/v1/exception:192:18:注意:要匹配此“(”字符 使用嵌套的(_Tp&&u t,typename enable_,如果< ^ /usr/bin/。/lib/c++/v1/异常:213:19:错误:使用未声明的标识符 '是'的基础' _base_为::value吗 ^ /usr/bin/。/lib/c++/v1/exception:211:18:注意:要匹配此“(”字符 使用嵌套的(_Tp&&u t,typename enable_,如果< ^ test.cpp:4:20:错误:无法创建非聚合类型“std::vector” 使用初始值设定项列表初始化 std::向量vec1{1,2,3}; ^ ~~~~~~~ test.cpp:5:20:错误:无法创建非聚合类型“std::vector” 使用初始值设定项列表初始化 向量vec2={1,2,3}; ^ ~~~~~~~ 产生了14个错误。
-stdlib=libc++
添加到编译器标志。有关说明,请参阅。

解决方案 具体来说,我必须转到XCode首选项->下载并安装“命令行工具”。这解决了问题

解释 发生的只是一个简单的过时软件的例子。由于OSX是最新的(通过软件更新),我假设所有的XCode和编译器更新都已经到位。事实并非如此


注意,在对问题的评论中,我说“我有最新版本的XCode for Lion”。但我没有。(bames53在他的回答中暗示了这一点)仅仅因为OSX软件更新中没有任何新的更新并不意味着你有最新的XCode编译器。你可以通过XCode首选项来更新它

在乔纳森的反馈和谷歌搜索的帮助下,解决了我的问题

这实际上更新了llvm工具链

$ c++ --version
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

您正在使用的版本是:

Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
虽然上面说的是“3.1”,但实际上与你所看到的“3.1”并不相同。苹果版本和LLVM.org版本基本上是不相关的

Apple clang 3.1版是“基于LLVM 3.1svn”,这意味着它基于LLVM.org源代码库中“LLVM.org 3.1”之前的版本,可能不具备最终LLVM.org 3.1版本的所有功能


Apple clang 3.1现在已经有点过时了。从那时起,LLVM.org已经发布了“3.1”和“3.2”版本,而Apple已经发布了“Apple clang 4.1”我认为。你应该更新Xcode,或者看看是否在其他地方安装了更新版本的clang。

已经尝试过了。不起作用。请看我对问题的编辑。我确实意识到,考虑到我问题的原始内容,正确的答案是添加--stdlib=libc++,尽管我已经尝试过了,但这本身就是否定的还不够。可能重复并查看详细解释第二个错误似乎是libc++中的一个错误,它没有实现您正在使用的功能。尝试升级到LLVM/Clang/libc++3.2并正确格式化整个块,只需粘贴它,然后选择整个块并按Ctrl-K(或文本框上方的{}图标)我有最新版本的XCode for Lion。这是否意味着Lion上的XCode已损坏?我不想升级我的操作系统,也不想走达尔文端口的道路。@Spundun-请注意,“Apple clang version 3.1”与“LLVM clang 3.1”不同。在Mountain Lion上