I would like to write a "portable" C++ library in Clang. "Portable" means that I detect (in C preprocessor) what C++ features are available in the compilation environment and use these features or provide my workarounds. This is similar to what Boost libraries are doing.
However, the presence of some features depends not on the language, but on the Standard Library implementation. In particular I am interested in:
initializer_list
being constexpr
. I find this problematic because Clang by default does not use its own Standard Library implementation: it uses libstdc++. While Clang has predefined preprocessor macros __GNUC__
, __GNUC_MINOR__
, __GNUC_PATCHLEVEL__
, they are hardcoded to values 4, 2, 1 respectively, and they tell me little about the available libstdc++ features.
How can I check in Clang preprocessor what version of libstdc++ it is using?
The process for checking your installed version of libc will be the same regardless of your Linux distro. Simply use the ldd command as seen below. $ ldd --version ldd (Ubuntu GLIBC 2.35-0ubuntu3) 2.35 ... As you can see from the first line of the output and in the previous screenshot, we have version 2.35 installed.
This happens even when the libstdc++ is installed and the file is available in /usr/local/lib/libstdc++.so. By default, the ds_agent looks for the required library in the /opt/ds_agent/lib folder.
Clang supports use of either LLVM's libc++ or GCC's libstdc++ implementation of the C++ standard library.
Libstdc++ is part of the GCC sources. You should first unpack the GCC tarball and change to the gcc-9.2.
Clang does come with its own standard library implementation, it's called libc++. You can use it by adding -stdlib=libc++
to your compile command.
That being said, there are various ways to check Clang/libstdc++ C++ support:
__has_feature
macro (and friends) that can be used to detect language features and language extenstions.And also, this took me 2 minutes of googling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With