You can check if your headers are from glibc in C++ using several approaches:
Preprocessor macros:
#include <iostream>
int main() {
#ifdef __GLIBC__
std::cout << "Using glibc version " << __GLIBC__ << "." << __GLIBC_MINOR__ << std::endl;
#else
std::cout << "Not using glibc" << std::endl;
#endif
return 0;
}
Check for glibc-specific headers:
#include <iostream>
#ifdef __has_include
#if __has_include(<gnu/libc-version.h>)
#include <gnu/libc-version.h>
#define HAS_GLIBC_VERSION_H
#endif
#endif
int main() {
#ifdef HAS_GLIBC_VERSION_H
std::cout << "GNU libc version: " << gnu_get_libc_version() << std::endl;
#else
std::cout << "gnu/libc-version.h not found - probably not glibc" << std::endl;
#endif
return 0;
}
Check feature test macros:
#include <iostream>
#include <features.h> // This header defines __GLIBC__ if using glibc
int main() {
#ifdef __GNU_LIBRARY__
std::cout << "GNU C Library detected" << std::endl;
#endif
#ifdef __GLIBC__
std::cout << "Definitely using glibc" << std::endl;
#endif
return 0;
}
At compile time, you can also check:
echo | g++ -E -dM -x c++ - | grep -i glibc
echo | g++ -E -dM -x c++ - | grep __GLIBC__
This will show you all predefined macros, including glibc-related ones if present.
Check your include paths:
g++ -E -x c++ - -v < /dev/null 2>&1 | grep -A 10 "include"
This shows where your compiler is looking for headers. Glibc headers are typically in /usr/include with glibc-specific subdirectories like /usr/include/gnu/.
The __GLIBC__ macro is the most reliable way to detect glibc at compile time. If it's defined, you're using glibc headers.