Can I determine which compiler/linker flags where used to create a binary-only shared library?

扶醉桌前 提交于 2019-12-05 17:30:42

问题


I am wondering if there is a way to find out which g++ compiler/linker flags where used in creating a binary-only library.

For example there might be a 3rd party shared library (only .h/.so files are there).

So I think it would be a good idea to use the same g++ flags when compiling and linking my own application (that is using the binary-only 3rd party library).

Specifically I am asking for compiler flags like

  • -fno-inline
  • -pthreads
  • -mtune=arch
  • -O2

and also it would be of interest which linker flags have been used:

  • -fpic or -fPIC
  • -fexceptions
  • -pthreads

and so on.


回答1:


There is no systematic way of doing this. You can look if the library is linked to libpthread as an indication of whether -pthreads was used. For PIC/non-PIC code, you may want to try this. Optimization level, tuning and others will be much harder to determine.




回答2:


I don't believe so as there does not appear to be a section in the ELF format for that information. On Linux, if you use 'readelf -a' to dump all the information, there's nothing about how the file got that way.



来源:https://stackoverflow.com/questions/2276561/can-i-determine-which-compiler-linker-flags-where-used-to-create-a-binary-only-s

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