如何通过宏检查是否使用了 GNU libstdc++? [英] How can I check via macro whether the GNU libstdc++ is used?
问题描述
如何通过宏检查是否使用了 (GNU GCC) libstdc++ STL 实现?那可能吗?我想让它同时在 GCC 和 Clang 中工作.
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.
对于 Linux 上的 C++11,它可能是唯一的选择(或者是吗?).(STLport 不支持 C++11,AFAIK.)在 MacOSX 上,(LLVM)libc++ STL 更有可能,如果您使用 Clang(可能也用于 GCC,不确定).
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).
推荐答案
您可以检查 __GLIBCXX__
(或 __GLIBCPP__
,对于 3.4.0 之前的版本)宏是否存在,在包含一个 C++ 标准包含文件之后(cstddef
是一个不错的选择):
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
在此处阅读更多信息:
- 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
这篇关于如何通过宏检查是否使用了 GNU libstdc++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!