How to detect -stdlib=libc++ in the preprocessor?

后端 未结 1 1145
抹茶落季
抹茶落季 2020-12-20 12:00

I think this is part of the problem at No type named \'unique_ptr\' in namespace \'std\' when compiling under LLVM/Clang. According to Marshall Clow, I can detect -std

相关标签:
1条回答
  • 2020-12-20 12:24

    The only effect -stdlib=libc++ has on the preprocessor is to change the include paths it uses to find standard library headers, so you can't detect the presence of -stdlib=libc++ on the command-line per se, you can only detect which standard library headers get included. Obviously you can't detect that without actually including one or more standard library headers.

    If you include any libc++ header then _LIBCPP_VERSION will be defined, so the way to detect -stdlib=libc++ is to include at least one C++ library header and check for _LIBCPP_VERSION.

    For libc++ it is recommended to #include <ciso646> which serves no purpose in C++ and declares nothing, but for libc++ does define the _LIBCPP_VERSION macro. However, for libstdc++ historically <ciso646> did not define any macros such as __GLIBCXX__ that can be used to detect libstdc++. That changed with GCC 6.1 so <ciso646> can be used now, but for older releases you need to include a different header to detect libstdc++.

    0 讨论(0)
提交回复
热议问题