Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

stl

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

like image 664
Albert Avatar asked Sep 17 '14 13:09

Albert


People also ask

Is Libstdc ++ part of GCC?

Libstdc++ is part of the GCC sources. You should first unpack the GCC tarball and change to the gcc-9.2.

Are there any macros for libstdc++ library version information?

These macros cannot be redefined . A select handful of macros control libstdc++ extensions and extra features, or provide versioning information for the API. Only those macros listed below are offered for consideration by the general public. Below are the macros which users may check for library version information.

What is the __gnuc__ macro in GCC?

When compiling with GCC it has the same value as GCC's pre-defined macro __GNUC__ . This macro can be used when libstdc++ is used with a non-GNU compiler where __GNUC__ is not defined, or has a different value that doesn't correspond to the libstdc++ version.

Is Libstdc++ known to all compilers?

It is known to majority of compilers. You should also use C_INCLUDE_PATH and/or CPLUS_INCLUDE_PATH. These two a more gcc specific (other compilers prefer INCLUDE without language separation). You can also ignore the environment variables completely and specify the correct libstdc++ directly in the command line.

What version of glibc do I need for libstdc++?

All GNU/Linux distros make more recent versions available now. libstdc++ 4.6.0 and later require glibc 2.3 or later for this localization and formatting code. The guideline is simple: the more recent the C++ library, the more recent the C library. (This is also documented in the main GCC installation instructions.) 4.8.


1 Answers

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
like image 165
Vanni Totaro Avatar answered Sep 28 '22 15:09

Vanni Totaro