Get compilation info of an installed program

2019-09-17 09:09发布

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.

1条回答
够拽才男人
2楼-- · 2019-09-17 09:25

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)

查看更多
登录 后发表回答