How to list on-the-fly all the functions/symbols available in C code on a Linux architecture?

后端 未结 5 1524
悲&欢浪女
悲&欢浪女 2020-12-08 14:54

Assume main.c uses symbols from shared libs and local functions declared in main.c.

Is there a nice and elegant way to print a list of all

5条回答
  •  难免孤独
    2020-12-08 15:37

    This is not really C specific, but operating system and binary format and (for debugging symbols and unmangled C++ symbol names) even compiler specific question. There is no generic way, and also no truly elegant way.

    The most portable and future-proof way is probably running external program such as nm, which is in POSIX. GNU version found in Linuxes probably has a bunch of extensions, which you should avoid if you aim for portability and future-proofness.

    Its output should stay stable, and even if binary formats change, it will also get updated and keep working. Just run it with right switches, capture its output (probably by running it through popen to avoid a temp file) and parse that.

提交回复
热议问题