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
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++.