How would you list the available functions etc contained within a compiled library?

a 夏天 提交于 2020-12-21 17:40:51

问题


How do I determine whether a function exists within a library, or list out the functions in a compiled library?


回答1:


You can use the nm command to list the symbols in static libraries.

nm -g -C <libMylib.a>



回答2:


For ELF binaries, you can use readelf:

readelf -sW a.out | awk '$4 == "FUNC"' | c++filt

-s: list symbols -W: don't cut too long names

The awk command will then filter out all functions, and c++filt will unmangle them. That means it will convert them from an internal naming scheme so they are displayed in human readable form. It outputs names similar to this (taken from boost.filesystem lib):

285: 0000bef0    91 FUNC    WEAK   DEFAULT   11 boost::exception::~exception()

Without c++filt, the name is displayed as _ZN5boost9exceptionD0Ev




回答3:


For Microsoft tools, "link /dump /symbols <filename>" will give you the gory details. There are probably other ways (or options) to give an easier to read listing.




回答4:


Under Linux/Unix you can use objdump -T to list the exported symbols contained in a given object. Under Windows there's dumpbin (IIRC dumpbin /exports). Note that C++ function names are mangled in order to allow overloads.

EDIT: after seeing codelogic's anwser I remembered that objdump also understands -C to perform de-mangling.




回答5:


use this command:

objdump -t "your-library"

It will print more than you want - not just function names, but the entire symbol table. Check the various attributes of the symbols you get, and you will be able to sort out the functions from variables and stuff.



来源:https://stackoverflow.com/questions/392142/how-would-you-list-the-available-functions-etc-contained-within-a-compiled-libra

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