nm报告符号已定义,但ldd报告符号未定义

编程入门 行业动态 更新时间:2024-10-28 18:32:24
本文介绍了nm报告符号已定义,但ldd报告符号未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到链接问题.我需要链接到共享库libfoo.so,该库依赖于函数read,我想在文件read.c中定义自己.

I'm having a linking problem. I need to link against a shared library libfoo.so that depends on a function read which I would like to define myself in the file read.c.

我将所有内容编译并链接在一起,但是在运行时出现错误

I compile and link everything together but at runtime I get the error

/home/bar/src/libfoo.so: undefined symbol: sread.

nm报告符号已定义

$nm baz | grep sread 00000000000022f8 t sread

但是ldd报告该符号未定义

but ldd reports the symbol is undefined

$ldd -r baz | grep sread undefined symbol: sread (/home/bar/src/libfoo.so)

有什么作用? libfoo.so是共享库是否存在一些问题?

What gives? Is there some isse with the fact that libfoo.so is a shared library?

推荐答案

首先,定义一个名为"read"的函数不是一个好主意,因为它是所有UNIXen上的标准libc函数.执行此操作时,程序的行为是不确定的.

First, defining a function called 'read' is a bad idea(TM), because it is a standard libc function on all UNIXen. The behavior of your program is undefined when you do this.

第二,在libbaz.so中定义的read函数在nm输出中标记为't'.这意味着此功能是本地功能(在libbaz.so外部不可见).全局功能由nm用'T'标记.

Second, the read function you defined in libbaz.so is marked with a 't' in nm output. This means that this function is local (not visible outside libbaz.so). Global functions are marked with 'T' by nm.

在read.c中定义'static int read(...)'时是否使用过? 如果没有,那么在编译并链接libbaz.so时是否在命令行中使用了链接脚本,attribute((visibility(hidden)))或-fvisibility=hidden?

Did you use 'static int read(...)' when you defined it in read.c? If not, did you use a linker script, or attribute((visibility(hidden))), or perhaps -fvisibility=hidden on command line when you compiled and linked libbaz.so?

更多推荐

nm报告符号已定义,但ldd报告符号未定义

本文发布于:2023-10-30 12:24:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   报告   定义   未定义   nm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!