TFLite Porting遇到的 undefined symbol问题

因为编译的目标是动态文件 so, 所以上面编译通过并没有万事大吉,当加载so时出现了 undefined symbol问题,当时有点慌,其实,这是常见问题。
_ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv     
_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcj
_ZNSt3__112__next_primeEj
_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev        
_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_
_ZNSt3__16__sortIRNS_6__lessIiiEEPiEEvT0_S5_T_
_ZNSt11logic_errorC2EPKc

c++filt

C++的函数、变量名编译器会加入参数等信息变成上面的样子,看不出原来的样子,没有办法在代码里搜索等。这种常见问题工具总是有的(特别感谢:《程序员的自我修养: 链接、装载与库》): c++filt

c++filt _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
std::__1::__vector_base_common<true>::__throw_length_error() const

从名字std::, __可以判断出是个库函数,这个库函数包含在那个库里,是不是没有链接对应的库导致的?下个问题应该用那个名字搜索?_ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv还是__throw_length_error。答案是前者,因为是包含在库中,所有是plus plus后的名字:_ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv

直接搜索,看那个Binary file里有matched: grep


Binary file ./libc++abi.so.1.0 matches
Binary file ./libc++.so.1.0 matches
 

 objdump:看库是定义了函数还是引用,找到定义的库


  -t, --syms               Display the contents of the symbol table(s)
  -T, --dynamic-syms       Display the contents of the dynamic symbol table
➜  lib git:(master) ✗ objdump -t libc++.so.1.0 | grep _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
0000000000069c90  w    F .text    0000000000000057              _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
➜  lib git:(master) ✗ objdump -t libc++abi.so | grep _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
0000000000009e70  w    F .text    0000000000000020              _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv

F . text表示这里是定义不是引用:下面的就是引用: F UND

objdump -t libLW.so | grep _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
0000000000000000       F *UND*    0000000000000000              _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv
 

其他也是这种方法,找到对应的库,大多情况下,找到一个后面的大都依赖相同的库

libstdc++.a -->  libc++.a

libstdc++ 是GUN实现的库, libc++是llvm实现的库,

libstdc++.a: 2100 而libc++.a: 64912

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值