eva*_*ing 2 c++ macos xcode c++11
我已经构建了自己的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;
});
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,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};
Run Code Online (Sandbox Code Playgroud)
好的,我需要一个支持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>
Run Code Online (Sandbox Code Playgroud)
我的解决方案是使用-I并-L指向我手动编译的libc ++.
假设我将与之分享的人没有那个,但至少有XCode.我该怎么做才能使上面的代码变得复杂?当然OS X必须附带C++ 11功能???
[编辑]
事实证明,因为我安装llvm与来自homwbrew的xcode,当我这样做时clang出现了which clang.我认为来自自制软件的clang不会被符号化,/usr/local/bin但显然它确实如此.所以我想从中学到的经验(以前很多次)是从不假设RTFM!
最近的Xcode版本将clang和libc ++头文件放在Xcode.app中.控制单击它并选择"显示包内容"以导航到此目录.
确保命令行clang与Xcode.app中的命令行相同:
$ which clang++
Run Code Online (Sandbox Code Playgroud)
为了我:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/clang++
Run Code Online (Sandbox Code Playgroud)
和:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/lib/c++/v1
Run Code Online (Sandbox Code Playgroud)