简体   繁体   English

取决于具有未定义符号的共享库

[英]Depending on a shared library that has an undefined symbol

I am trying to build a shared library that depends on another shared library on which I have no control. 我试图建立一个共享库,该库依赖于我无法控制的另一个共享库。 Here is how I build it: 这是我的构建方法:

g++ -fPIC -Wall -Wextra -O2 -g -fpermissive -Wl,--no-allow-shlib-undefined -Wl,--no-undefined \
    -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -I/opt/softkinetic/DepthSenseSDK/include \
    -L/opt/softkinetic/DepthSenseSDK/lib \
    -lDepthSense -lDepthSensePlugins -lturbojpeg -c -o NativeDs325.o \
     NativeDs325.cpp

g++ -shared -o libds325.so NativeDs325.o

The build step goes fine, but when I load my library, it throws an undefined symbol error . 构建步骤进行得很好,但是当我加载库时,它将引发undefined symbol error When I look into the libraries, here is what I found 当我查看库时,这是我发现的

$ldd -d libds325.so
    linux-vdso.so.1 =>  (0x00007fff94bfe000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f727167d000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7271467000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72710a6000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7270daa000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7271ba5000)
    undefined symbol: _ZTIN10DepthSense9ExceptionE  (./libds325.so)
    undefined symbol: _ZTIN10DepthSense16EventHandlerBaseE  (./libds325.so)
    undefined symbol: _ZN10DepthSense7ContextD1Ev   (./libds325.so)
    undefined symbol: _ZN10DepthSense9DepthNodeD1Ev (./libds325.so)

And when I look into the library I depend on and on which I have no control: 当我查看库时,我依赖并且无法控制:

$nm -D libds325.so | grep _ZTIN10DepthSense9ExceptionE
    U _ZTIN10DepthSense9ExceptionE
$nm -D libds325.so | grep _ZTIN10DepthSense16EventHandlerBaseE                                                                                                  
    U _ZTIN10DepthSense16EventHandlerBaseE

So those symbols are not defined in the libraries I have. 因此,这些符号未在我拥有的库中定义。 Is there anything I can do to solve my problem or am I totally dependent on the supplier of the library? 有什么我可以解决的问题,还是我完全依赖图书馆的供应商? Is there something I'm missing entirely? 有什么我完全想念的吗?

Thanks in advance 提前致谢

You could try to figure out what the function signatures you need are, build your own .so defining those symbols and use that to get past the undefined symbol error. 您可以尝试找出所需的函数签名,构建自己的.so定义这些符号,然后使用它来克服未定义的符号错误。 If you're really determined you might be able to reverse engineer what the functions/missing classes do. 如果您真的确定,则可以对功能/缺失类的功能进行反向工程。

Realistically though, you should contact the provider of the libraries with this information and get libs with the necessary symbols defined. 但实际上,您应该将此信息与库的提供者联系,并获取具有已定义必要符号的库。

I had two problems in the way I was building the library: 建立图书馆的方式有两个问题:

1) As per this question undefined reference to symbol even when nm indicates that this symbol is present in the shared library , libraries must be listed after the objects that use them so: 1)根据这个问题,即使nm表示共享库中存在此符号,也未定义对符号的引用,因此必须在使用它们的对象之后列出库:

g++ NativeDs325.cpp -fPIC -Wall -Wextra -O2 -g -fpermissive -Wl,--no-allow-shlib-undefined -Wl,--no-undefined \
-I$JAVA_HOME/include -I$JAVA_HOME/include/linux -I/opt/softkinetic/DepthSenseSDK/include \
-L/opt/softkinetic/DepthSenseSDK/lib \
-lDepthSense -lDepthSensePlugins -lturbojpeg -c -o NativeDs325.o \

2) When linking, I needed to add the libraries to include in the final shared library: 2)链接时,我需要添加要包含在最终共享库中的库:

g++ -shared -o libds325.so NativeDs325.o -L/opt/softkinetic/DepthSenseSDK/lib \
 -lDepthSense -lDepthSensePlugins -lturbojpeg

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

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