我已经构建了自己的 libc++ 并且通常将其包含在-I /path/to/lib/include -L /path/to/lib/lib
。但现在我必须与其他使用 Mac 的人共享一个项目,我想给他们一个“正常工作”® 的 Makefile™。
考虑以下程序:
#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;
});
}
当我编译它时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};
好的,我需要一个支持 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>
我的解决方案是使用-I
and -L
指向我手动编译的libc++。
假设我要与之分享的人没有这个,但至少有 XCode。我该怎么做才能使上面的代码复制?当然 OS X 必须附带 C++11 功能???
[EDIT]
事实证明,自从我用 homwbrew 的 xcode 安装了 llvm 后,当我这样做时,clang 就出现了which clang
。我认为自制程序中的 clang 不会被符号链接到/usr/local/bin
但显然确实如此。所以我想吸取的教训(就像之前很多次一样)是永远不要假设,而是 RTFM!