c++ - 在 xcode 4.6 中构建但使用命令行失败

标签 c++ macos clang xcode4.6

当我从 Xcode4.6 运行以下代码片段时,它编译并运行良好。但是当我尝试使用命令行工具 (clang++) 编译它时,它失败了。

#include <iostream>
#include <memory>

int main(int argc, const char * argv[])
{

    std::unique_ptr<int> foo(new int(0));

    // insert code here...
    std::cout << "Hello, this is cool giri World!\n";
    return 0;
}

编译日志如下:

$ clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

$ clang++ main.cpp -stdlib=libc++ -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/ -I /usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include/ 
main.cpp:7:10: error: no member named 'unique_ptr' in namespace 'std'
    std::unique_ptr foo(new int(0));
    ~~~~~^
main.cpp:7:24: error: expected '(' for function-style cast or type construction
    std::unique_ptr foo(new int(0));
                    ~~~^
main.cpp:7:26: error: use of undeclared identifier 'foo'
    std::unique_ptr foo(new int(0));
                         ^
3 errors generated.

最佳答案

尝试使用 clang 自己的标准库:

clang -std=c++11 -stdlib=libc++ main.cpp

默认是 GNU 的标准库 (libstdc++),但 Apple 包含的版本很旧,不支持 C++11。

关于c++ - 在 xcode 4.6 中构建但使用命令行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14829166/

相关文章:

c++ - 当使用可变长度参数列表(...)时,除了通过 va_list 前进之外,您还能做任何事情吗?

c# - Windows Mobile 6 接听多个电话

macos - 在 Mac OS X 上设置 ANDROID_HOME 环境变量

macos - 从 Mac OS X Yosemite 卸载 BetterTouchTool。无法删除,因为 "App is currently open"

c++ - 如何获取我当前正在使用 Clang 访问的文件的名称?

c++ - 如何将 boost_threads 与 clang 一起使用?

c++ - 如何使用 make_heap 在 C++ 中创建最小堆

c++ - 特征矩阵的下三角

python - 类型错误 : '<' not supported between instances of 'PrefixRecord' and 'PackageRecord' while updating Conda

c++ - clang++ (3.3/Xcode) 中 std::function 的定义在哪里