0

I need to obtain the information on the C-compiler used to build an installed program. I am guessing a rt or a lib can report that, but nothing concrete. Not that the program would be installed in /usr/... or a similar place, and hence would not have access to the build directory to get the relevant info.

Ankesh Anand
  • 1,695
  • 2
  • 16
  • 24

1 Answers1

2

Well behaved programs should understand the --version argument.

Packaged programs (i.e. those installed with dpkg -i or apt-get install of a .deb package on Debian, etc...) also know their package version and source.

You might try to use strings on the binary executable. However, such meta-data (about the version of the C compiler used to build the program) might have been stripped (e.g. by the strip command).

If you are developing the program (i.e. its C source code) and can change it, you might consider adding something like

timestamp.c: Makefile
      echo 'const char timestamp[]=' > $@
      date +'"built with $(shell $(CC) --version) on %c";' >> $@

yourprogram: $(OBJECTS) timestamp.o
      $(LINK.c) $(LDFLAGS) $< -o $@ $(LDLIBES)
      $(RM) timestamp.c

in your Makefile (details could be wrong, but you get the idea)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • None of them work. I am one of the developers of the program, and need to extract the compilation info of the installed program(which is a shell script). Any other possible solutions? – Ankesh Anand Mar 14 '14 at 17:40
  • 1
    @AnkeshAnand compilation info of the shell script?.. Or whatever this supposed to mean? – keltar Mar 14 '14 at 17:43
  • Sorry, I messed things up, ignore the shell script part. I want the compilation info of the binaries. – Ankesh Anand Mar 14 '14 at 17:45
  • If it is a shell script, you don't need any compiler to run or install it. – Basile Starynkevitch Mar 14 '14 at 17:46
  • No, it's not a shell script, they are a bunch of C-files, producing a binary. – Ankesh Anand Mar 14 '14 at 17:47
  • @AnkeshAnand generally you can't, unless you've implemented it yourself (this answer shows how). Other option would be to build program with every possible compiler on the _same_ machine and same environment and compare resulting binaries (`diff`, `sha1sum`, whatever), but it will only work on completely matching environments and compilation flags. – keltar Mar 14 '14 at 17:57
  • `objdump(1)` might give some hints – vonbrand Mar 14 '14 at 20:08