mac c ++编译器找不到< tr1/unordered_map> [英] mac c++ compiler not finding <tr1/unordered_map>

查看:355
本文介绍了mac c ++编译器找不到< tr1/unordered_map>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想今天的问题是哪个" c ++编译器是Mac上的默认编译器?

I guess the question of the day is "which" c++ compiler is the default on mac?

如果我执行xcrun -find c++,则表示它在/Applications/Xcode.app/etc...中.

If I do xcrun -find c++ it says it's in /Applications/Xcode.app/etc....

当我在Xcode目录中搜索tr1/unordered_map时,它就在那里.

When I search the Xcode directory for tr1/unordered_map, it's there.

所以我很困惑.为什么我收到一个显示fatal error: 'tr1/unordered_map' file not found的构建错误?

So I'm confused. Why am I getting a build error that says fatal error: 'tr1/unordered_map' file not found?

推荐答案

简短的回答:使用-stdlib=libstdc++调用clang ++,并且tr1标头会在那里.

Short answer: call clang++ with -stdlib=libstdc++, and the tr1 headers will be there.

长答案: 错误的原因和包括两组C ++的原因是macOS/Xcode具有两个可以针对其构建的C ++标准库:一个旧的GNU libstdc++和一个新的和现代的LLVM libc++.

Long answer: The reason for your error and the 2 sets of C++ includes is that macOS/Xcode has two different C++ standard libraries you can build against: an old GNU libstdc++, and the new and modern LLVM libc++.

从macOS 10.12 Sierra开始,默认值现在为libc++,而已弃用libstdc++. libstdc++很老,v4.2.1,且早于C ++ 11(因此,tr1标头).如果您要长期使用此代码,则值得花时间使其至少符合C ++ 11(即#include <unordered_map>)

As of macOS 10.12 Sierra, the default is now libc++ and libstdc++ is deprecated. libstdc++ is quite old, v4.2.1, and predates C++11 (hence the tr1 headers). If you're going to be using this code long-term, it'd be worth the time to at least make it C++11 compliant (i.e. #include <unordered_map>)

更新:Xcode 10不再允许针对libstdc ++进行构建.更新您的代码库以使用标准的C ++ 11标头,或者如果确实没有选择,请使用Xcode 9.

Update: Xcode 10 no longer allows building against libstdc++. Either update your codebase to use standard C++11 headers, or use Xcode 9 if that's really not an option.

这篇关于mac c ++编译器找不到&lt; tr1/unordered_map&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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