Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if glibc is used

Tags:

c++

c

glibc

I am trying to implement backtrace functionality for a large framework, which is used for different platforms and OS'es. In some of them, it is linked against glibc, while in the other, something different (eg. uclibc) is used. backtrace() function exists only in the former.

Is there any way to tell whether glibc is used? Any #define? I was unable to find an answer in glibc manual. I know I can't have linking-time information during compilation, but I guess include files have to differ. At least backtrace have to be declared somewhere. I would like to check it without being forced to pass explicit flags to the compiler.

like image 363
x13n Avatar asked Nov 24 '10 11:11

x13n


People also ask

What version of glibc am I running?

Another method is to "type" the glibc library (i.e., libc. so. 6 ) from the command line as if it were a command. The output will show more detailed information about glibc library, including the version of glibc and the GNU compiler used, as well as available glibc extensions.

Where is glibc used?

What is glibc? The GNU C Library project provides the core libraries for the GNU system and GNU/Linux systems, as well as many other systems that use Linux as the kernel. These libraries provide critical APIs including ISO C11, POSIX. 1-2008, BSD, OS-specific APIs and more.


2 Answers

Include features.h, it contains the macros you need, e.g.

#define __GNU_LIBRARY__ 6  /* Major and minor version number of the GNU C library package.  Use    these macros to test for features in specific releases.  */ #define __GLIBC__       2 #define __GLIBC_MINOR__ 4 
like image 188
Erich Kitzmueller Avatar answered Oct 09 '22 16:10

Erich Kitzmueller


There are the #defines __GNU_LIBRARY__, __GLIBC__ and __GLIBC_MINOR__ (6, 2 and 11 on my system with glibc-2.11) in features.h.

like image 33
Gunther Piez Avatar answered Oct 09 '22 16:10

Gunther Piez