问题描述
我有一个ANSI C程序,该程序使用通过RTLD_LAZY的dlopen()动态加载.so文件.我收到
I have an ANSI C program that dynamically loads a .so file using dlopen() passing RTLD_LAZY. I receive
Undefined symbol "_nss_cache_cycle_prevention_function"
在FreeBSD 7.2中访问.so文件时发出警告. nss_cache_cycle_prevention_function()不是我程序的功能之一,我想一定是来自FreeBSD的.尽管我在Linux上没有遇到过这个问题,但这在Linux上也可能是一个问题.我不想将FreeBSD特定的头文件加载到我的程序中.我想以可移植的方式包含此功能,或者禁止显示这些警告.
warnings whenever the .so file is accessed in FreeBSD 7.2. nss_cache_cycle_prevention_function() is not one of my program's functions and I imagine must be coming from FreeBSD. This might also be a problem on Linux too although I am not experiencing the issue there. I would prefer not to load FreeBSD specific header files into my program. I would like to either include this function in a portable way or suppress these warnings.
推荐答案
您说我收到警告"是什么意思?你的程序吗检查dlerror()
返回的值,如果不为NULL,则打印该值?
What do you mean saying "I receive warning"? Does your programexamine the value returned by dlerror()
and prints it if it is not NULL?
_nss_cache_cycle_prevention_function
是一个标记符号,由FreeBSD上的nsdispatch(3)
使用它来确定是否使用nscd(8)
的服务,即名称服务缓存守护程序.完全不存在它是完全正常的可执行文件或共享库.
The _nss_cache_cycle_prevention_function
is a marker symbol which is used by nsdispatch(3)
on FreeBSD to determine whether to employ the services of nscd(8)
, the name service caching daemon. It is perfectly normal that it does not exist in anexecutable or a shared library.
但是,当nsdispatch(3)
执行dlsym(3)
且未找到符号时,将设置错误.并且dlerror(3)
返回 last 错误的描述,而不是最后 call 错误的描述.我怀疑那就是你要击中的东西.
But when nsdispatch(3)
executes dlsym(3)
, and the symbol is not found, the error will be set. And dlerror(3)
returns the description of the last error, and not the description of the error of the last call. I suspect that's what you are hitting.
解决方案(非常便于携带)将是:
The solution (quite portable) would be to:
- 对于
dlopen(3)
,请先检查其返回值,然后再使用dlerror()
查看是否存在错误; 对于 - ,因为
NULL
是有效的返回值,在调用dlsym(3)
之前的 无效上下文中调用dlerror()
;这样可以清除之前的所有错误,从而使以后再次调用dlerror(3)
的第二次调用都可以被信任.
dlsym(3)
,- for
dlopen(3)
, check its return value before usingdlerror()
to see whether there was an error at all; - for
dlsym(3)
, sinceNULL
is a valid return value,to calldlerror()
in a void context before the call todlsym(3)
; that will clear any previous error, so that whatever the second call todlerror(3)
returns later on can be trusted.
通常,在其他任何dl *调用之前调用空的dlerror()
不会有任何损害.
In general, it will not harm anything to call an empty dlerror()
before any other dl* calls.
这篇关于dlerror:未定义符号"_nss_cache_cycle_prevention_function";在FreeBSD 7.2上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!