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"®.
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.cc
I naturally get errors that relate to missing -std=c++11
flag. Ok, so lets add it clang++ -std=c++11 -o test test.cc
. That gives several errors, one of which is
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.
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 -I
and -L
pointing to my manually compiled 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???
[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/bin
but apparently it did. So I guess the lesson learnt (as so many times before) is to never assume but to RTFM!