使用独立工具链为armeabi-v7a
构建c ++库已成功。
但是,在Unity中加载时,我会丢失符号错误:
05-11 17:05:32.029 12064 12082 D Unity : Unable to load library '/data/app/com.xxx.yyy.app-geDNMNRtyT09WKhCcElqhg==/lib/arm/lib***.so', native render plugin support disabled: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSsD1Ev" referenced by "/data/app/com.xxx.yyy.app-geDNMNRtyT09WKhCcElqhg==/lib/arm/lib***.so"...
即std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
。
用nm
检查编译的库时,我看到此符号确实未定义:
$ nm lib***.so
U _ZNSsD1Ev
我还可以看到该库依赖于共享的libstdc++.so
:
$ readelf -d build/lib/lib***.so
...
0x00000001 (NEEDED) Shared library: [libsqlite3.so]
0x00000001 (NEEDED) Shared library: [libopenssl.so]
0x00000001 (NEEDED) Shared library: [libndn-cpp.so]
0x00000001 (NEEDED) Shared library: [liblog.so]
0x00000001 (NEEDED) Shared library: [libOpenSLES.so]
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
...
即使我使用-static-libstdc++
设置了自动工具:
CFLAGS="-isystem $TOOLCHAIN/include/c++/4.9.x/ --sysroot=$TOOLCHAIN/sysroot -I$TOOLCHAIN/sysroot/usr/include -I$TOOLCHAIN/include"
CPPFLAGS="-isystem $TOOLCHAIN/include/c++/4.9.x/ --sysroot=$TOOLCHAIN/sysroot -I$TOOLCHAIN/sysroot/usr/include -I$TOOLCHAIN/include -DWEBRTC_POSIX -DBOOST_ASIO_DISABLE_STD_CHRONO $CPPFLAGS -DWEBRTC_POSIX -DBOOST_ASIO_DISABLE_STD_CHRONO -g -O0"
CXXFLAGS="$CXXFLAGS -DWEBRTC_POSIX -DBOOST_ASIO_DISABLE_STD_CHRONO -g -O0"
LDFLAGS="-static-libstdc++ -L$TOOLCHAIN/sysroot/usr/lib -L$TOOLCHAIN/arm-linux-androideabi/lib -L$TOOLCHAIN/arm-linux-androideabi/lib/armv7-a -lOpenSLES -lm -lsqlite3 -lopenssl"
有趣的是,当我搜索工具链的库时,缺少的符号仅显示在libgnustl_shared.so
中:
$ nm $TOOLCHAIN/arm-linux-androideabi/lib/armv7-a/libgnustl_shared.so | grep "_ZNSsD1Ev"
00096568 W _ZNSsD1Ev
不太确定为什么会这样,因为据我所知,libgnustl_shared.so
没有(明显)依赖性。