Get compilation info of an installed program

断了今生、忘了曾经 提交于 2019-12-13 04:29:48

问题


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:


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)



来源:https://stackoverflow.com/questions/22411837/get-compilation-info-of-an-installed-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!