title: Determining compiler and version used to build a shared object on *ix operating system
body: <p>I work on some software that loads a set of user specified shared objects.
  I'd like to add some code to our "loader" component that can query each specified shared object 
  and find out what compiler and what compiler version was used to build/link that shared object.</p>
  
  <p>In the past, I've been able to use a "strings -a  | grep " approach as shown below.
  However, this approach is not working for code compiled with g++ 4.8 on power AIX, 
  and it's not working particularly well for code compiled with g++ 4.8 on x86 linux.</p>
  
  <p>I would also love to find some cleaner way of obtaining this information than grepping for strings if possible. </p>
  
  <p><strong>Can anyone provide advice on how to query a shared object for the name of the compiler that built it and also the version of that compiler?</strong></p>
  
  <hr>
  
  <p><em>Here's some example command and output from my current technique:</em></p>
  
  <p><strong>on an x86 linux g++ 4.1 compiled shared object:</strong></p>
  
  <pre><code>$ strings -a libshareme.so | grep GNU
  GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-50)
  &lt;etc&gt;
  </code></pre>
  
  <p>(lots of repetitive output here, but it's clear that the version is GCC 4.1.2)</p>
  
  <p><strong>on a power AIX xlC v11 compiled object</strong></p>
  
  <pre><code>$ strings -a libshareme.so | grep XL
  XL  
  IBM XL C/C++ for AIX, Version 11.1.0.6
  IBM XL C/C++ for AIX, Version 10.1.0.6
  </code></pre>
  
  <p>(kind of confusing that it shows v11 and v10, but XL C is clear) </p>
  
  <p><strong>on an x86 linux g++ 4.8 compiled shared object:</strong></p>
  
  <pre><code>$ strings -a libshareme.so | grep GNU
  GCC: (GNU) 4.4.6 20120305 (Red Hat 4.4.6-4)
  GCC: (GNU) 4.8.2 20131111 (Red Hat 4.8.2-4)
  GNU C++ 4.8.2 20131111 (Red Hat 4.8.2-4) -m32 -mtune=generic -march=i686 -g -fmessage-length=0 -fPIC
  </code></pre>
  
  <p>(also kind of confusing here that it shows multiple versions)</p>
  
  <p><strong>on a power AIX g++ 4.8 compiled object</strong></p>
  
  <pre><code>$ strings -a libshareme.so | grep GNU
  &lt;no output&gt;
  </code></pre>
  
  <p>On x86/linux, I usually see a "GNU" type string in 'strings -a' output I can match. However, using strings -a on this libshareme.so compiled on power/aix with g++4.8 doesn't show me anything obvious regarding compiler version. </p>