-1

If I take a C or C++ library in Windows, Linux or Mac, is there any way to know what functions and data structures it exports and their signatures without having documentation of this library?

Incerteza
  • 32,326
  • 47
  • 154
  • 261
  • What do you mean by "export"? Symbols visible to the linker or identifiers declared in a header? – mafso Aug 02 '14 at 16:48
  • 1
    That kind of depends. If you have headers for it (for one example) that will tell you functions and structrues (but not necessarily much about how to use them). If you just have the library proper (.lib, .a, .so, etc.) then you can usually get a fair amount of information for C++ (based on name mangling) but much less for C (since it doesn't normally use name mangling). – Jerry Coffin Aug 02 '14 at 16:48
  • considering that the linker can check it, the answer must logically be "yes" (although not necessarily full info on the data structures). that's trivial logic. are you asking for specifics of the ways? in that case, please do supply details of the kinds of libraries and the specific toolchains. – Cheers and hth. - Alf Aug 02 '14 at 16:48
  • 1
    There are tools to inspect what a `.dll` exports, yes. You may want to check the [Dependency Walker tool](http://www.dependencywalker.com/) for instance. – πάντα ῥεῖ Aug 02 '14 at 16:49
  • possible duplicate of [How to print a list of symbols exported from a dynamic library](http://stackoverflow.com/questions/4506121/how-to-print-a-list-of-symbols-exported-from-a-dynamic-library) – Jongware Aug 02 '14 at 18:32
  • 1
    @Jongware: This question appears to include static libraries as well. – Ben Voigt Aug 02 '14 at 18:36

1 Answers1

6

You can definitely list the symbol names used by the linker. For C++, this is a complete (mangled) signature. For C (also applies to extern "C" in C++), it's often little more than the bare name (sometimes the total size of arguments, but without types, size of each, or even the number of arguments).

On Unix systems, the tool you want is nm (or objdump, which can additionally show symbols without linkage). On Windows, DUMPBIN /EXPORTS.

If trying to inspect static libraries, you may have to extract them first (ar on Unix, lib.exe on Windows) and call nm or dumpbin on the individual members (object files).

See this related question for details about getting the C++ signatures: Finding arguments that go with methods in C++ dll's

Debug information may also provide access to C linkage signatures, since they aren't stored in the symbol table.

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • The OS X command (which is most likely for what OP calls "Mac") is `nm` as well. – Jongware Aug 02 '14 at 18:34
  • @Jongware: OS X and Linux are both Unixy systems (OS X is BSD). – Ben Voigt Aug 02 '14 at 18:34
  • The OP seems unaware of that. – Jongware Aug 02 '14 at 18:37
  • 1
    @Jongware: An Apple II is not a Macintosh. There were, however, System 7, Mac OS 8, Mac OS 9 prior to the adoption of BSD with OS X. (I think those were NeXt-based?) – Ben Voigt Aug 02 '14 at 18:38
  • Yah, sorry 'bout that - realized it too late. Still, OP ought to write "OS X" instead of "Mac". I's a bit like "I have an IBM at home", meaning a - Windows compatible - PC. (Even the word "PC" is not politically correct anymore.) – Jongware Aug 02 '14 at 20:13