我有一个C
使用两个libraries
libA和libB的程序。问题是; 这两个库都具有list_delete函数,这是编译器错误。通过编写这些行,我能够成功编译并链接我的代码。
#undef list_delete
#define list_delete mysql_list_delete
之后,我可以在我的代码中调用libA的list_delete函数。但是,当我调用libB的任何函数(list_delete除外)时,会在内部调用list_delete函数,而该函数恰好是libA的list_delete函数。
为什么?libB应该在内部调用list_delete函数,而不是libA的list_function。
问题是如何告诉libB库使用其自己的list_delete函数(请记住,我的程序正在使用libA的list_delete函数)
使用dlopen和RTLD_DEEPBIND加载库解决了该问题。
dlopen(“ libB”,RTLD_LAZY | RTLD_DEEPBIND);
RTLD_DEEPBIND (since glibc 2.3.4) Place the lookup scope of the symbols in this library ahead of the global scope. This means that a self-contained library will use its own symbols in preference to global symbols with the same name contained in libraries that have already been loaded. This flag is not specified in POSIX.1-2001.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句