How to compile #include <experimental/any> for clang on OSX

杀马特。学长 韩版系。学妹 提交于 2019-12-08 01:57:49

问题


I am trying to get the #include <experimental/any> to compile in my C++ program on clang OSX

// test.cpp
#include <experimental/any>

int main() {
  return 0;
}

Tried following commands/options as learnt from here

clang++ -std=c++14 test.cpp -o test -std=c++1z -stdlib=libc++
clang++ -std=c++1x test.cpp -o test -std=c++1z -stdlib=libc++
clang++ -std=c++1y test.cpp -o test -std=c++1z -stdlib=libc++
clang++ -std=c++1z test.cpp -o test -std=c++1z -stdlib=libc++

But it doesn't compile & complains of the following error:

fatal error: 'experimental/any' file not found

clang++ --version yields following:

Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

How can I get #include <experimental/any> to compile?

Should I upgrade clang on my machine?

Is C++17 supported on clang currently as of today? If yes how can get the support for it?


回答1:


For OSX 10.12.5 (using Xcode Developer tools), we get

> clang++ -v
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

and there is no any in /Library/Developer/CommandLineTools/usr/include/c++/v1/experimental, but only

chrono
optional    
string_view 
tuple
utility
algorithm
dynarray    
ratio   
system_error    
type_traits

So, it appears that Apple's libc++ does not provide any (there is no any in /Library/Developer/CommandLineTools/usr/include/c++/v1/ either). You must either use GCC or your own clang or boost/any.hpp, all of which you can install via homebrew.




回答2:


You misspelt it. It's "experimental", not "experimentals".

However, since Clang 4.0, you should just be using <any>.



来源:https://stackoverflow.com/questions/44119464/how-to-compile-include-experimental-any-for-clang-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!