evading
evading

Reputation: 3090

Where is libc++ on OS X?

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!

Upvotes: 5

Views: 15152

Answers (2)

micfan
micfan

Reputation: 840

OS X El Capitan 10.11.6 (15G1004)

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/

Upvotes: 0

Howard Hinnant
Howard Hinnant

Reputation: 218740

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.

Ensure that your command line clang is the same one that is inside your 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

Upvotes: 7

Related Questions