【问题标题】:Depending on a shared library that has an undefined symbol取决于具有未定义符号的共享库
【发布时间】:2014-05-09 16:51:40
【问题描述】:

我正在尝试构建一个依赖于另一个我无法控制的共享库的共享库。这是我的构建方式:

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

构建步骤很顺利,但是当我加载我的库时,它会抛出一个undefined symbol error。当我查看图书馆时,这是我发现的

$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)

当我查看我所依赖且无法控制的库时:

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

所以这些符号没有在我拥有的库中定义。我可以做些什么来解决我的问题,还是我完全依赖图书馆的供应商?有什么我完全想念的吗?

提前致谢

【问题讨论】:

  • 您很可能缺少一个库....试图查看 DepthSense 库...发行说明提到了一个核心库...
  • 好的,谢谢,您在哪里找到这些发行说明?在 linux sdk 中没有找到它们
  • 盲目搜索:link
  • 实际上我不确定库在编译时是否正确链接(参见 ldd 的输出,它甚至没有提到库)

标签: c++ compiler-construction linker shared-libraries missing-symbols


【解决方案1】:

您可以尝试找出您需要的函数签名是什么,构建您自己的 .so 定义这些符号并使用它来克服未定义符号错误。如果你真的确定你可以逆向工程函数/缺失类的作用。

实际上,您应该联系库的提供者并提供此信息,并获取定义了必要符号的库。

【讨论】:

    【解决方案2】:

    我在构建库的过程中遇到了两个问题:

    1) 根据这个问题undefined reference to symbol even when nm indicates that this symbol is present in the shared library,库必须列在使用它们的对象之后:

    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) 链接时,我需要添加要包含在最终共享库中的库:

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

    【讨论】:

      猜你喜欢
      • 2011-02-28
      • 2016-10-16
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 2015-03-08
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多