xcode OS X 上的 libc++ 在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15981424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is libc++ on OS X?
提问by evading
I have built my own libc++ and I usually include it with -I /path/to/lib/include -L /path/to/lib/lib. But now I have to share a project with someone else with a Mac and I want to hand them a Makefile? that "just works"?.
我已经构建了自己的 libc++,我通常将它包含在-I /path/to/lib/include -L /path/to/lib/lib. 但是现在我必须与使用 Mac 的其他人共享一个项目,我想给他们一个 Makefile?那个“正常工作”?。
Consider the following program:
考虑以下程序:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
uint32_t nums[100];
for (size_t i = 0; i < 10; ++i)
{
nums[i] = 666;
}
vector<int> hello{1, 2, 3, 4, 5, 6, 7, 8};
for_each(hello.begin(), hello.end(), [](int tal)
{
cout << tal << endl;
});
}
When I compile it with clang++ -o test test.ccI naturally get errors that relate to missing -std=c++11flag. Ok, so lets add it clang++ -std=c++11 -o test test.cc. That gives several errors, one of which is
当我编译它时,clang++ -o test test.cc我自然会得到与缺少-std=c++11标志相关的错误。好的,让我们添加它clang++ -std=c++11 -o test test.cc。这给出了几个错误,其中之一是
test.cc:15:17: error: no matching constructor for initialization of 'vector<int>'
vector<int> hello{1, 2, 3, 4, 5, 6, 7, 8};
Ok, I need a C++11 capable C++ library.
好的,我需要一个支持 C++11 的 C++ 库。
clang++ -std=c++11 -stdlib=libc++ -o test test.cc
test.cc:1:10: fatal error: 'algorithm' file not found
#include <algorithm>
My solution to this has been to use -Iand -Lpointing to my manually compiled libc++.
我对此的解决方案是使用-I并-L指向我手动编译的 libc++。
Assuming that the person I will share this with doesn't have that but has at least XCode. What can I do to make the above code copile? Surely OS X must ship with C++11 capabilities???
假设我将与之分享这个的人没有那个但至少有 XCode。我该怎么做才能使上面的代码复制?当然 OS X 必须附带 C++11 功能???
[EDIT]
[编辑]
Turns out that since I installed llvm with xcode from homwbrew that clang was showing up when I did which clang. I assumed that clang from homebrew would not get symlinked into /usr/local/binbut apparently it did. So I guess the lesson learnt (as so many times before) is to never assume but to RTFM!
事实证明,自从我从 homwbrew 安装了带有 xcode 的 llvm 之后,当我这样做时,clang 出现了which clang。我认为来自自制软件的叮当声不会被符号链接,/usr/local/bin但显然它确实如此。所以我想学到的教训(就像以前很多次一样)是永远不要假设,而是去 RTFM!
回答by Howard Hinnant
Recent Xcode releases put both clang and libc++ headers inside of the Xcode.app. Control click on it and choose "Show Package Contents" to navigate into this directory.
最近的 Xcode 版本将 clang 和 libc++ 头文件都放在 Xcode.app 中。控制单击它并选择“显示包内容”以导航到此目录。
Ensure that your command line clang is the same one that is inside your Xcode.app:
确保您的命令行叮当声与您的 Xcode.app 中的相同:
$ which clang++
For me:
为了我:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/clang++
and:
和:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/lib/c++/v1
回答by micfan
OS X El Capitan 10.11.6 (15G1004)
OS X El Capitan 10.11.6 (15G1004)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/

