c++ - MacPorts Clang 3.1 缺少标准库安装?

标签 c++ c++11 clang macports c++-standard-library

我正在尝试使用 MacPorts 安装的 clang 在 C++11 中初始化列表功能。编译这段简单的代码时:

#include <vector>

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

我遇到了这个错误:

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.

它似乎包含来自系统 gcc (4.2) 的 header 。而且我找不到任何特定于 clang 的 header 。我应该从 MacPorts 安装什么包才能工作?或者我是否需要安装和构建 clang 的 libc++?

最佳答案

首先,您需要使用“-stdlib=libc++”设置标准库

那么您可能需要更新标题。最新的 libc++ header 将与随 OS X 10.7 及更高版本安装的 libc++ 库一起使用。

我不知道 macports 有 libc++,但由于您只需要 header ,您应该能够简单地下载它们并将它们放入与 clang 安装位置相邻的 include 目录中。

关于c++ - MacPorts Clang 3.1 缺少标准库安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10415095/

相关文章:

gcc - 带有自定义 gcc 安装的 LIBRARY_PATH 的优先级

clang - 在 Travis CI 上为 C++17 设置 Clang

c++ - 铿锵错误 : non-const lvalue reference cannot bind to incompatible temporary

c++ - 绑定(bind)到引用丢弃限定符时出错

c++ - 将常量 double 映射到整数的现代 C++ 方法

c++ - std::string::substr 返回的对象的生命周期

c++ - #定义C++中的常量

c++ - strcpy 和 strcmp,我做错了什么?

c++ - 我必须将哪些参数传递给函数才能执行对象的隐式构造?

c++ - 错误 : cannot convert in arguement passing