Compruebe la versión de glibc para un compilador gcc en particular


Tengo dos compiladores gcc instalados en mi sistema, uno es gcc 4.1.2 (por defecto) y el otro es gcc 4.4.4. ¿Cómo puedo comprobar la versión libc utilizada por gcc 4.4.4, porque /lib/libc.so.6 muestra el glibc utilizado por gcc 4.1.2, ya que es el compilador predeterminado.

 29
Author: MetallicPriest, 2012-03-14

6 answers

Escribir un programa de prueba (nombrarlo por ejemplo glibc-version.c):

#include <stdio.h>
#include <stdlib.h>
#include <gnu/libc-version.h>

int main(int argc, char *argv[]) {
  printf("GNU libc version: %s\n", gnu_get_libc_version());
  exit(EXIT_SUCCESS);
}

Y compilar con el compilador gcc-4.4:

gcc-4.4 glibc-version.c -o glibc-version

Cuando ejecuta ./glibc-version se muestra la versión glibc utilizada.

 25
Author: R1tschY,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-14 16:39:45

Uso -print-file-name gcc opción:

$ gcc -print-file-name=libc.so
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/libc.so

Que da el camino. Ahora:

$ file /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/libc.so
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/libc.so: ASCII C program text

$ cat /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/libc.so
/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )

Parece un script enlazador. libc es especial en Linux en que se puede ejecutar:

$ /lib64/libc.so.6
GNU C Library stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.5.1 20100924 (Red Hat 4.5.1-4).
Compiled on a Linux 2.6.35 system on 2011-08-05.
Available extensions:
    Support for some architectures added on, not maintained in glibc core.
    The C stubs add-on version 2.1.2.
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
    RT using linux kernel aio
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
 28
Author: Maxim Egorushkin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-14 22:26:48

Aún más fácil

Use ldd version version

Esto debería devolver la versión glibc que se está utilizando, es decir,

$ ldd --version

ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

...

Que es el mismo resultado que ejecutar mi biblioteca libc

$ /lib/libc.so.6 


GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.

...

 18
Author: John,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-26 09:29:39

Dudo que tenga más de un glibc instalado en su sistema.Pero ldd -v <path/to/gcc-4.x> debería darte el glibc usado.

 8
Author: itisravi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-14 16:51:37

gnu_get_libc_version identifica la versión runtime de la Biblioteca C de GNU.

Si lo que te importa es la versión en tiempo de compilación (es decir, la versión que proporcionó los encabezados en /usr/include), deberías mirar las macros __GLIBC__ y __GLIBC_MINOR__. Estos se expanden a enteros positivos, y se definirán como un efecto secundario de incluir cualquier archivo de encabezado proporcionado por la Biblioteca C de GNU; esto significa que puede incluir un encabezado estándar y luego usar #ifdef __GLIBC__ para decidir si puede incluya un encabezado no estándar como gnu/libc-version.h.

Expandiendo el programa de prueba desde la respuesta aceptada:

#include <stdio.h>
#ifdef __GLIBC__
#include <gnu/libc-version.h>
#endif

int
main(void)
{
#ifdef __GLIBC__
  printf("GNU libc compile-time version: %u.%u\n", __GLIBC__, __GLIBC_MINOR__);
  printf("GNU libc runtime version:      %s\n", gnu_get_libc_version());
  return 0;
#else
  puts("Not the GNU C Library");
  return 1;
#endif
}

Cuando compilo y corro este programa en la computadora en la que estoy escribiendo esta respuesta (que es una Mac) imprime

Not the GNU C Library

Pero cuando se compila y se ejecuta en una caja Linux cercana imprime

GNU libc compile-time version: 2.24
GNU libc runtime version:      2.24

En circunstancias normales, la versión "runtime" podría ser más grande que la versión "compile-time", pero nunca más pequeña. El número de versión principal es poco probable que cambiar de nuevo (la última vez que cambió fue la "transición libc6" en 1997).

Si prefiere un shell 'one-liner' para volcar estas macros, use:

echo '#include <errno.h>' | gcc -xc - -E -dM | 
    grep -E '^#define __GLIBC(|_MINOR)__ ' | sort

El patrón grep se elige para que coincida solo con las dos macros que son relevantes, porque hay docenas de macros internas llamadas __GLIBC_somethingorother que no desea tener que leer.

 7
Author: zwol,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-14 17:01:41

Puede usar el comando strings para comprobar la versión de GLIBC del compilador. La versión más alta es aplicable.

ubuntu1604:extra$ strings ./arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc | grep GLIBC
    GLIBC_2.3
    GLIBC_2.8
    GLIBC_2.14
    GLIBC_2.4
    GLIBC_2.11
    GLIBC_2.2.5
    GLIBC_2.3.4
 -1
Author: Neeraj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-29 10:33:25