How can I check via macro whether the GNU libstdc++ is used?

百般思念 提交于 2019-12-23 11:47:35

问题


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

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