问题
How can I check via macro whether the (GNU GCC) libstdc++ STL implementation is used? Is that possible? I would like to have that working in both GCC and Clang.
For C++11 on Linux, it's probably anyway the only choice (or is it?). (STLport doesn't have C++11 support, AFAIK.) On MacOSX, (LLVM) libc++ STL is more likely, if you use Clang (maybe also for GCC, not sure).
回答1:
You can check for __GLIBCXX__
(or __GLIBCPP__
, for releases before 3.4.0) macro existence, after including one of the C++ standard include files (cstddef
is a good choice):
#include <cstddef>
#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
/* Using GNU GCC libstdc++, so using also its STL implementation */
#endif
Read more here:
- https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
- https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html
- https://gcc.gnu.org/onlinedocs/gcc-4.9.1/cpp/If.html
来源:https://stackoverflow.com/questions/25891868/how-can-i-check-via-macro-whether-the-gnu-libstdc-is-used