如何找出给定对象所在的库?

发布于 2024-07-09 03:08:57 字数 278 浏览 10 评论 0原文

我正在运行 Irix 6.5 的 SGI 上使用 FORTRAN 和 C 进行编程,但这应该适用于所有类 Unix 系统。 当出现“无法解析的文本符号”链接错误时,如何找到需要链接到程序的库? 这是我从链接器中看到的示例:

ld32: ERROR  33 Unresolved text symbol "ortho2_" -- first referenced by ./libfoo.a

我是否只需要知道需要哪些库,或者是否有一些工具或命令可以帮助我解决这个问题?

I'm programming in FORTRAN and C on an SGI running Irix 6.5, but this should be applicable to all Unix-like systems. How do I find which library I need to link to my program when I get an "unresolved text symbol" link error? Here's an example of what I'm seeing from the linker:

ld32: ERROR  33 Unresolved text symbol "ortho2_" -- first referenced by ./libfoo.a

Do I just have to know which libraries are required, or is there some tool or command that can help me figure this out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

时间你老了 2024-07-16 03:08:57

您可以使用 nm 命令列出共享库中的动态符号:

nm -D /lib/libc.so.6

然后使用 grep 命令查找您要查找的符号。 对于静态库,省略 -D。 您可以在循环中使用它或与 xargs 一起使用它来扫描多个库。

我通常只使用谷歌(假设该符号来自公开可用的库)。

You can use the nm command to list the dynamic symbols from a shared library:

nm -D /lib/libc.so.6

and then grep for the symbol you are looking for. Omit the -D for static libraries. You can use this in a loop or with xargs to scan multiple libraries.

I usually just use google (assuming the symbol is from a publicly available library).

画▽骨i 2024-07-16 03:08:57

使用 nm (如 罗伯特·甘布尔的回答)是您问题的正确答案。 诀窍在于知道在哪里寻找图书馆。 你的程序是做什么的? 如果存在大量数字,您很可能应该链接到数学库(例如 LAPACK 或 BLAS),并且可能想要开始在那里查找。 Web 搜索也很有帮助 - 我在我最喜欢的搜索引擎中输入“ortho2”并得到 此文档表明它位于 libfgl.a

请注意,当您搜索时,您可能应该省略尾部下划线 - 它通常会添加到例程中由编译器命名。

Using nm (as in Robert Gamble's answer) is the correct answer to your question. The trick is in knowing where to look for the libraries. What does your program do? If there is a large amount of numerics going on, chances are you should be linking against math libraries (like LAPACK or BLAS) and might want to start looking there. Web searching can also be helpful - I typed "ortho2" into my favorite search engine and got this documentation that suggests it's in libfgl.a

Note that when you search you should probably omit the trailing underscore - it's usually added to the routine name by the compiler.

十年不长 2024-07-16 03:08:57

我抵制住了将其添加到罗伯特·甘布尔的答案中的诱惑——将其视为对其的补充。

请警惕简单地假设“任何匹配”都可以使用。 在另一个 SO 问题中存在一个情况,其中一段代码从 Windows 移动到 Unix,并且 Windows 代码使用 getch() 从输入中读取单个字符。 用户经历了与此类似的过程,并在 Unix 上的 curses 库中找到了 getch()。 因此,用户链接到curses库并想知道为什么代码核心被转储。 问题是,实际使用的 getch() 假设已经完成了正确的初始化,而正确的初始化尚未完成。 事实上,这可能不是我们所需要的例行公事。

在 Solaris 上,nm 有一些选项可以告诉您库名称,甚至是库中包含该符号的目标文件(-r 表示库名称,< code>-R 用于库内的对象)。

也要小心 C++ 损坏的名称。 ortho2 示例显然不是 C++ 损坏的。

I resisted the temptation to add this to Robert Gamble's answer - consider this a supplement to it.

Be wary of simply assuming that 'any match' is OK for use. There was a case in another SO question where a piece of code was moved from Windows to Unix and the Windows code used getch() to read a single character from the input. The user went through a process analogous to this and found getch() on Unix in the curses library. So, the user linked with the curses library and wondered why the code core dumped. The trouble is, the getch() actually used assumes that the proper initialization has been done, and the proper initialization was not done. In fact, it probably wasn't the routine that was needed.

On Solaris, there are options to nm that tell you the library name and even object file within the library that contains the symbol (these are -r for library name, and -R for object within library).

Beware C++ mangled names, too. The ortho2 example is clearly not C++ mangled.

戏蝶舞 2024-07-16 03:08:57

如果它是标准函数(ortho2 可能是),则手册页会告诉您它位于哪个库中。

If it's a standard function, which ortho2 could be, the man page will tell you which library it is in.

十六岁半 2024-07-16 03:08:57

我有一个小的查找脚本。 输入查找 func_name

#!/bin/csh
foreach i (*.o *.a *.so)
 echo $i
 nm $i | grep -i $1
end

I have a little lookfor script. Enter lookfor func_name

#!/bin/csh
foreach i (*.o *.a *.so)
 echo $i
 nm $i | grep -i $1
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文