如何判断某个库是否使用某些GCC版本进行了编译 [英] How to tell if a library is compiled with certain GCC version

查看:65
本文介绍了如何判断某个库是否使用某些GCC版本进行了编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Unix计算机上编译OpenSSL.默认的编译器是 GCC-4.4.7 .我将另一个编译器 GCC-5.2.0 放在另一个文件夹中.通常,我会将替代编译器的路径添加到 $ PATH 的前面,以便 gcc 始终使用替代编译器的路径.

I'm compiling OpenSSL on Unix-machine. The default compiler is GCC-4.4.7. I put an alternative compiler GCC-5.2.0 in another folder. I usually will prepend the path of alternative compiler to $PATH so that gcc will always use the one in alternative path.

但是现在我不确定我编译的库,有没有办法知道哪个gcc用于编译我的库?也欢迎使用 .o 文件的解决方法.

But now I'm uncertain with the library I compiled, is there a way to tell which gcc is used for compiling my library? A workaround on the .o files is appreciated as well.

推荐答案

gcc和clang编译器套件会将版本字符串放在ELF文件的 .comment 部分中.(如果生成中间汇编语言文件,则可以将该字符串作为 .ident 指令查看).

The gcc and clang compiler suites will put a version string in the .comment section of an ELF file. (If you generate an intermediate assembly language file, you can see this string as an .ident directive).

GNU链接器会将其输入对象文件的所有 .comment 部分合并为一个部分,从而消除了重复项.

The GNU linker will merge all the .comment sections of its input object files into a single section, eliminating any duplicates.

您可以通过运行 readelf -p .comment/path/to/your/objectfile 阅读本节.例如,这是一个由两个可重定位目标文件制成的可执行文件,一个使用gcc编译,另一个使用clang编译:

You can read this section by running readelf -p .comment /path/to/your/objectfile. For example, here is an executable made from two relocatable object files, one compiled with gcc and the other with clang:

$ readelf -p .comment hello

String dump of section '.comment':
  [     0]  GCC: (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
  [    2d]  clang version 3.8.1-12ubuntu1 (tags/RELEASE_381/final)

这篇关于如何判断某个库是否使用某些GCC版本进行了编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆