OS X上的libc ++在哪里? [英] Where is libc++ on OS X?

查看:371
本文介绍了OS X上的libc ++在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了自己的libc ++,通常将它包含在-I /path/to/lib/include -L /path/to/lib/lib中.但是,现在我必须与其他使用Mac的人共享一个项目,我想向他们提供一个可以正常使用"的Makefile™.

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"®.

请考虑以下程序:

#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.这给出了几个错误,其中一个是

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};

好的,我需要一个具有C ++ 11功能的C ++库.

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>

对此,我的解决方案是使用-I-L指向我手动编译的libc ++.

My solution to this has been to use -I and -L pointing to my manually compiled libc++.

假定与我共享此人的人没有,但至少具有XCode.我该怎么做才能使以上代码变得可修改?当然,OS X必须附带C ++ 11功能?

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???

结果表明,由于我使用homwbrew的xcode安装了llvm,所以在执行which clang时会显示叮当声.我假设来自自制程序的clang不会被符号链接到/usr/local/bin中,但是显然可以.因此,我想(以前有很多次)吸取的教训是永远不要去假设而是去RTFM!

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!

推荐答案

最近的Xcode版本将clang和libc ++头文件都放在Xcode.app中.按住Control键单击它,然后选择显示包内容"以导航到该目录.

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.app内部的叮当声相同:

Ensure that your command line clang is the same one that is inside your Xcode.app:

$ which clang++

对我来说

/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/clang++ 

和:

/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/lib/c++/v1

这篇关于OS X上的libc ++在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆