title: How to check libc version?
body: <p>This question is related to <a href="https://stackoverflow.com/questions/62724531/why-does-pclose-return-prematurely">Why does pclose return prematurely?</a>. <strong>I'd like to find out what version of <code>libc</code> is used for a cross-compiled executable.</strong> There are limitations, described below, that make the answers at <a href="https://stackoverflow.com/questions/9705660/check-glibc-version-for-a-particular-gcc-compiler">Check glibc version for a particular gcc compiler</a> not apply.</p>
  <ul>
  <li><p>One proposed way to check the <code>libc</code> version is to use the <code>gnu_get_libc_version()</code> function declared in <code>gnu/libc-version.h</code>. My cross-toolchain does not include <code>libc-version.h</code>.</p>
  </li>
  <li><p>Another proposed solution is to use the <code>-print-file-name</code> <code>gcc</code> option. This answer in the linked question just flat-out didn't work for me:</p>
  </li>
  </ul>
  <pre><code>$ /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc -print-file-name=libc.so
  libc.so
  $
  $ /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc -print-file-name=foo.bar
  foo.bar
  $ # I really do not have a foo.bar file in existence
  </code></pre>
  <ul>
  <li>Another proposed solution is to just do <code>ldd --version</code>. My target platform doesn't have <code>ldd</code>:</li>
  </ul>
  <pre><code>$ ldd
  sh: can't execute 'ldd': No such file or directory
  </code></pre>
  <ul>
  <li>Another proposed solution is to look at <code>__GLIBC__</code> and <code>__GLIBC_MINOR__</code> -- but these also appear to come from <code>libc-version.h</code>, which doesn't exist in my cross-toolchain, as described above.</li>
  </ul>
  <p>My cross-toolchain seems to only provide <code>libc.a</code>, not <code>libc.so</code>.<br />
  I tried running that <code>libc.a</code> through <code>/path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-nm</code> and <code>strings</code> grepping (case-insensitive) for &quot;version&quot; and &quot;libc&quot; but did not find anything that looked like an identifying version.</p>
  <p>The last thing I tried was <code>strings /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc | grep GLIBC</code>, which gave me:</p>
  <pre><code>GLIBC_2.3
  GLIBC_2.2
  GLIBC_2.1
  GLIBC_2.0
  EGLIBC configuration specifier, serves multilib purposes.
  </code></pre>
  <p>But that solution wasn't highly upvoted, and it also has a comment suggesting that it doesn't really give you the version. <em>I don't really understand this answer or its responding comment, so I don't know what to make of its validity.</em></p>
  <p><strong>Question: given all the above, is there any definitive way to determine the libc version used for cross-compiling for this cross-platform?</strong></p>