2

In Linux with gcc and glibc (version 2.24) is there a way to know which version of the C library was linked with by the compiler?

I'm looking for a way to have an output similar to this one:

This program was compiled using GCC and GNU glibc version 2.24

PS: It is very probable that this question is a duplicate, I just didn't really know what to exactly search for, it was easier to put the question in words rather that in search-engine keywords.

infotic
  • 187
  • 7
  • `file` and/or `ldd`? – edmz Jul 14 '17 at 15:46
  • 1
    but in almost all cases, programs are linked against `glibc` dynamically at runtime, not statically at compile time. So it's not which version "was" linked with; it would be whichever version is resolved during a specific run of the program. – underscore_d Jul 14 '17 at 15:47
  • Kind of surprising (I never took note)... `gcc -x c -dM -E - – jww Jul 14 '17 at 15:54
  • 2
    @jww You need to include at least one header provided by glibc for that to work, e.g. `echo '#include ' | gcc -x c -dM -E - | grep -E '^#define __(GLIBC|GNUC)(|_MINOR|_PATCHLEVEL)__\>' | sort` will bring up the macros you are looking for. (The `__GNUC*` macros, which give the _compiler_ version, are defined without including anything.) – zwol Jul 14 '17 at 16:05
  • 2
    @jww I will add an answer to the linked question. – zwol Jul 14 '17 at 16:40
  • 1
    The linked question is a bit different. If you can run `gcc`, you can certainly figure out which glibc version it picks up. However, just from the end result (the linked program) it is in general _impossible_ to figure out the glibc version which was used for the linking step. From the versions, you can only infer that the glibc version was at least this new. – Florian Weimer Jul 17 '17 at 11:03
  • @FlorianWeimer Yes it is a bit different, but people here like a lot to flag duplicate questions, it is some kind of national sport :) – infotic Jul 20 '17 at 02:02

0 Answers0