简体   繁体   English

动态加载到C程序中的对象在x86_64上给出未定义的符号错误

[英]dynamically loaded object loaded into a C program gives undefined symbol errors on x86_64

I have a C program that dynamically loads a .so file at runtime in order to connect to a MySQL database. 我有一个C程序,该程序在运行时动态加载.so文件以连接到MySQL数据库。 On an x86 (32bit) kernel this works fine but when I recompile my program on an x86_64 (64 bit) kernel I get runtime errors like this: 在x86(32位)内核上,它可以正常工作,但是当我在x86_64(64位)内核上重新编译程序时,会出现如下运行时错误:

dlerror:   mysql-1.932-x86_64-freebsd7.2.so::plugin_tweak_products: Undefined symbol "plugin_filter_cart"
dlerror:   mysql-1.932-x86_64-freebsd7.2.so::plugin_shutdown: Undefined symbol "plugin_post_action"

Obviously from the error message above you can see that this program is running on a FreeBSD 7.2 x86_64 machine. 从上面的错误消息中可以明显看出,该程序正在FreeBSD 7.2 x86_64计算机上运行。 Both the C program and the .so file are compiled for 64 bit. C程序和.so文件都被编译为64位。

I am passing RTLD_LAZY to dlopen() when I load the .so file. 加载.so文件时,我将RTLD_LAZY传递给dlopen()。 I think the problem is that for some reason on x86_64 it is not dynamically loading parts of the library as needed but on 32 bit x86 it is. 我认为问题是由于某种原因,在x86_64上它不是根据需要动态加载库的一部分,而在32位x86上却是。 Is there some flag I can put in my Makefile.am to get this to work on x86_64? 我可以在Makefile.am中放入一些标志来使其在x86_64上运行吗? Any other ideas? 还有其他想法吗?

Here is what the file command lists for my C program 这是文件命令为我的C程序列出的内容

ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), for FreeBSD 7.2, dynamically linked (uses shared libs), FreeBSD-style, not stripped

and for the .so file 和.so文件

ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), not stripped

Just a wild guess. 只是一个疯狂的猜测。 The prefix plugin seems to indicate there might be some callbacks with function pointers going on. 前缀plugin似乎表明可能存在一些回调,其中包含函数指针。 Also probably your compiler versions are not the same for 32 and 64 bit? 也可能您的编译器版本对于32位和64位是不同的吗? Do you use C99's or gcc's inline feature? 您是否使用C99或gcc的inline功能?

Such things can happen if one variant of your compiler is able to inline some function ( static or inline ) and the other doesn't. 如果您的编译器的一个变体能够内联某个函数( staticinline ),而另一个则不能,则可能发生这种情况。 Then an external symbol might be produced or not. 然后可能会生成外部符号,也可能不会生成。 This depends a lot of your compiler version, gcc had different strategies to handle such situations over time. 这取决于您的许多编译器版本,gcc随着时间的推移会采用不同的策略来处理此类情况。 Try to enforce the implementation of the function in at least one of your objects. 尝试在至少一个对象中强制执行该功能。 And as roguenut indicates, check with nm for the missing symbols. 如roguenut所指示,请用nm检查缺少的符号。

It looks like this was being caused by the same problem as 看来这是由于与

dlerror: Undefined symbol "_nss_cache_cycle_prevention_function" on FreeBSD 7.2 dlerror:FreeBSD 7.2上的未定义符号“ _nss_cache_cycle_prevention_function”

You need to call dlerror() first and ignore the return value to clear out errors from previous errors before you check the dlerror()'s return value. 您需要先调用dlerror()并忽略返回值以清除以前的错误,然后再检查dlerror()的返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM