nm报告符号已定义,但ldd报告符号未定义 [英] nm reports symbol is defined but ldd reports symbol is undefined

查看:325
本文介绍了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报告符号未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆