Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO Identify which GCC version built a binary
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2672
Location: here, there or in transit

PostPosted: Wed Dec 20, 2006 5:06 am    Post subject: HOWTO Identify which GCC version built a binary Reply with quote

This trick will let you determine which version(s) of GCC were used to compile and link a binary executable file:
Code:
strings -a /path/to/binary-file | grep "GCC:" | sort -u

Here is a dirt-simple scripted version of the pipeline.
which-gcc:
#!/bin/bash

if [ -z "$1" ] ; then
        echo "Usage: which-gcc file"
        echo "Determines GCC version(s) used to build file"
        exit
fi

strings -a $1 | grep "GCC:" | sort -u


Here are some examples from my system:
Code:
$ which-gcc /bin/bash
GCC: (GNU) 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)
I'm using GCC 3.4.6.

Code:
$ which-gcc `which vuescan`
GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
This commercial product was built on a Red Hat system, quite some time ago.

Code:
$ which-gcc /opt/google-earth/googleearth-bin
GCC: (GNU) 3.4.5 20050809 (prerelease) (Ubuntu 3.4.4-6ubuntu8)
GCC: (GNU) 4.0.2
The multiple version lines suggest Google Earth is at least in part statically linked. The final executable and at least one component library were built with different versions of GCC.

Code:
$ which-gcc /usr/bin/ooffice2

ooffice2 is not a GCC executable, thus no output. (It's a Bourne shell script. Reader exercise: produce a useful message when the file argument is not a GCC-created executable. :))

I needed this to answer a question this week and, upon seeing how neatly the information is presented, thought it might be useful to others.

EDIT: typo.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.


Last edited by timeBandit on Wed Dec 20, 2006 3:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
Mousee
Apprentice
Apprentice


Joined: 29 Mar 2004
Posts: 291
Location: Illinois, USA

PostPosted: Wed Dec 20, 2006 2:25 pm    Post subject: Reply with quote

Wow very nice!
Very useful on my VPS system, which still has some things I need to re-emerge without doing a whole 'emerge -e world'.
Many thanks :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum