C++ 如何在 Ubuntu 上的共享库中列出导出的函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2274617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:49:29  来源:igfitidea点击:

How to list exported functions in a shared lib on Ubuntu

c++ubuntulinker

提问by Stick it to THE MAN

I have just built a shared lib on Ubuntu, and when I attempt to use the function, the application that loads the library is reporting 'xxx' symbol not found.

我刚刚在 Ubuntu 上构建了一个共享库,当我尝试使用该函数时,加载库的应用程序报告找不到“xxx”符号。

I want to check (i.e. list) the functions that are exported by my library so I can investigate this issue further.

我想检查(即列出)我的库导出的函数,以便我可以进一步调查这个问题。

Relevant details:

相关详情:

OS: Ubuntu 9.10 compiler: gcc 4.4.1 linker: GNU ld 2.20

操作系统:Ubuntu 9.10 编译器:gcc 4.4.1 链接器:GNU ld 2.20

回答by rpg

Try the nm utility.

试试 nm 实用程序。

GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out. [reference]

GNU nm 列出目标文件 objfile... 中的符号。如果没有将目标文件列为参数,nm 假定文件 a.out。[参考]

回答by Mark

nm -D -C -g <library>

works well too.

效果也很好。

回答by Void

Is your shared library in the library load path or in the application's run-time search path? It sounds like the dynamic linker can't find your library. Try running lddon your application to see if the library can be found at run-time, e.g.:

您的共享库是在库加载路径中还是在应用程序的运行时搜索路径中?听起来动态链接器找不到您的库。尝试ldd在您的应用程序上运行以查看是否可以在运行时找到该库,例如

$ ldd /usr/bin/less
    linux-gate.so.1 =>  (0x0072a000)
    libncurses.so.5 => /lib/libncurses.so.5 (0x00c68000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x007c7000)
    libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00286000)
    /lib/ld-linux.so.2 (0x002a1000)

See the ld.so(8)man page for additional details on library search paths.

有关库搜索路径的更多详细信息,请参见ld.so(8)手册页。