编译这个文件时
#include <vector>
int main(int argc, char* argv[])
{
std::vector<int> IntVector;
}
使用 Xcode 附带的 clang 版本,我可以告诉 clang 像这样使用 llvm 的 libc++:
$ clang -std=c++11 -stdlib=libc++ t.cpp -lc++ -o t
但是,当使用自建版本的clang时,由于clang找不到libc++,这个命令不起作用:
$ /my/clang -std=gnu++11 -stdlib=libc++ t.cpp -lc++ -o t
t.cpp:1:10: fatal error: 'vector' file not found
#include <vector>
^
1 error generated.
我知道我可以从源代码下载、构建和安装 libc++;但是,我更愿意使用 Xcode 附带的版本。
在使用我自己的 clang 版本时,如何使用 Xcode 附带的 libc++ 版本?
最佳答案
首先确定 libc++ 的位置:它将位于 Xcode 应用程序本身内。如果您找不到它,请使用 Xcode 预处理 HelloWorld 并检查它是否有指向 std header 的路径。
然后在您的命令行上使用-I
指向include
目录。您还可以使用 -nostdinc++
来保证不会查找其他 std header :
$ /my/clang -std=gnu++11 -stdlib=libc++ t.cpp -nostdinc++ -I<path-to-libcxx>/include
关于c++ - 如何将 XCode 的 libc++ 与 top-of-trunk clang 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18792803/