使用dlopen()访问.so库会引发未定义的符号错误 [英] Accessing .so libraries using dlopen() throws undefined symbol error

查看:112
本文介绍了使用dlopen()访问.so库会引发未定义的符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将相机库.so文件动态加载到Linux可执行文件中,以访问简单的相机功能.

I'm trying to dynamically load a camera library .so file into a Linux executable to gain access to simple camera functions.

我正试图通过以下方式做到这一点:

I'm attempting to do this by:

  if ( (newHandle = dlopen("./libCamera.so",RTLD_LAZY | RTLD_GLOBAL)) == NULL )
  {
     printf( "Could not open file : %s\n", dlerror() );   
     return 1;
  }

但是这失败了,我收到以下输出:无法打开文件:libCamera.so:未定义的符号: ZTVN10 _cxxabiv117__class_type_infoE"

However this fails and I receive the following output: "Could not open file : libCamera.so: undefined symbol: ZTVN10_cxxabiv117__class_type_infoE"

如何找出它所依赖的符号?

How do I find out what symbols it is relying on?

推荐答案

libCamera.so 最有可能使用共享库中定义的符号,而不会依赖

Most likely, libCamera.so uses a symbol defined in a shared library without depending on that library.

  1. 找到一个元凶.以一个链接到 libCamera.so 的真实可执行文件为例(它可以工作).使用 ldd/path/to/executable 列出其依赖项.其中应有一个定义了 ZTVN10_cxxabiv117__class_type_infoE 的库(使用 grep 选择可能的候选库,以确保对库中的 nm -D ).该库不会出现在 ldd ./libCamera.so 所示的列表中.

  1. Find a culprit. Take a real executable which links against libCamera.so (and it works). List its dependencies with ldd /path/to/executable. Among them should be a library which has a definition for ZTVN10_cxxabiv117__class_type_infoE (use grep to select likely candidates, nm -D on a library to be sure). That library won't be in the list shown by ldd ./libCamera.so.

解决问题.首先通过 dlopen 加载在步骤1中找到的库(也可以在其中使用 RTLD_GLOBAL ).

Solve a problem. Load the library found in step 1 by dlopen first (use RTLD_GLOBAL there as well).

如果另一个符号有问题,请转到步骤1.

If there is a problem with another symbol, goto step 1.

如果新添加的库也存在相同的问题,请转到步骤1.

If newly-added libraries have the same problem too, goto step 1.

告诉图书馆作者,请修正他们的链接.

Tell library authors to please fix their linking.

还可能发生了 ldd ./libCamera.so 中的先决条件之一,升级并丢失了符号定义的情况(也许它是用名称不同的编译器重新编译的).然后,您将不会在步骤1中找到罪魁祸首,除了将某物降级之外,没有其他解决方案.

It could also happen that one of the prerequisites in ldd ./libCamera.so got upgraded and lost a symbol definition (maybe it was recompiled with a compiler which does name mangling differently). Then you won't find the culprit in step 1, and there is no solution but downgrading something again.

这篇关于使用dlopen()访问.so库会引发未定义的符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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