解决jni链接时找不到函数的问题
用jni调用库函数时,经常会碰到link的错误,具体出错信息如下:
08-07 01:42:06.490: E/AndroidRuntime(1665): java.lang.UnsatisfiedLinkError: xxxx
核对后发现函数名称并没有错。
这个问题有几种可能,最根本的解决方法是把so的内容dump出来。具体的方法可以参考 http://stackoverflow.com/questions/34732/how-do-i-list-the-symbols-in-a-so-file
我的文件是elf格式,执行如下的命令:
readelf -Ws xxxx.so >> test.log
so这个库导出的函数就在test.log里了,你可以在log找找看,如果没发现你要导出的函数,
大概有两种可能,第一个是JNIEXPORT没起到作用,第二个是你的函数名或者路径由错误。
附上我的test.log
Symbol table '.dynsym' contains 79 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000fa8 0 SECTION LOCAL DEFAULT 7
2: 0000aaa0 0 SECTION LOCAL DEFAULT 15
3: 00002278 36 FUNC GLOBAL DEFAULT 7 ___Unwind_ForcedUnwind
4: 00001c7c 164 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_RaiseException
5: 00000000 0 FUNC GLOBAL DEFAULT UND ioctl
6: 00000fdd 60 FUNC GLOBAL DEFAULT 7 Java_com_android_ralmes_GlobalProcess_read
7: 00001065 56 FUNC GLOBAL DEFAULT 7 Java_com_android_ralmes_GlobalProcess_isGpioTriggerDeviceExist
8: 00001019 76 FUNC GLOBAL DEFAULT 7 Java_com_android_ralmes_GlobalProcess_write
9: 00002134 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Save_VFP
10: 00002254 36 FUNC GLOBAL DEFAULT 7 _Unwind_Resume_or_Rethrow
11: 0000293c 0 NOTYPE GLOBAL DEFAULT ABS __exidx_end
12: 00000000 0 OBJECT GLOBAL DEFAULT UND __stack_chk_guard
13: 000017d4 8 FUNC GLOBAL DEFAULT 7 __aeabi_unwind_cpp_pr0
14: 00002360 44 FUNC GLOBAL DEFAULT 7 _Unwind_GetRegionStart
15: 00002254 36 FUNC GLOBAL DEFAULT 7 ___Unwind_Resume_or_Rethrow
16: 0000aab0 0 NOTYPE GLOBAL DEFAULT ABS _bss_end__
17: 0000229c 36 FUNC GLOBAL DEFAULT 7 _Unwind_Backtrace
18: 00000000 0 NOTYPE WEAK DEFAULT UND __cxa_begin_cleanup
19: 00002118 20 FUNC GLOBAL DEFAULT 7 __restore_core_regs
20: 00002154 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Save_VFP_D_16_to_31
21: 00000000 0 NOTYPE WEAK DEFAULT UND __cxa_call_unexpected
22: 00001304 8 FUNC GLOBAL DEFAULT 7 _Unwind_GetCFA
23: 00000000 0 FUNC GLOBAL DEFAULT UND memcpy
24: 000012a0 76 FUNC GLOBAL DEFAULT 7 _Unwind_VRS_Set
25: 00000000 0 FUNC GLOBAL DEFAULT UND __cxa_finalize
26: 0000a944 0 NOTYPE GLOBAL DEFAULT 12 __FINI_ARRAY__
27: 000011f1 100 FUNC GLOBAL DEFAULT 7 Java_com_android_ralmes_GlobalProcess_openGpioM0
28: 0000aaa0 0 NOTYPE GLOBAL DEFAULT ABS __bss_start__
29: 00001a18 212 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Backtrace
30: 0000aaa0 4 OBJECT GLOBAL DEFAULT 15 __dso_handle
31: 00002144 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Save_VFP_D
32: 00000000 0 FUNC GLOBAL DEFAULT UND __android_log_print
33: 00001dac 876 FUNC GLOBAL DEFAULT 7 _Unwind_VRS_Pop
34: 000017c4 8 FUNC WEAK DEFAULT 7 __aeabi_unwind_cpp_pr2
35: 0000229c 36 FUNC GLOBAL DEFAULT 7 ___Unwind_Backtrace
36: 0000285c 0 NOTYPE GLOBAL DEFAULT ABS __exidx_start
37: 0000220c 36 FUNC GLOBAL DEFAULT 7 ___Unwind_RaiseException
38: 00000000 0 FUNC GLOBAL DEFAULT UND abort
39: 00002230 36 FUNC GLOBAL DEFAULT 7 ___Unwind_Resume
40: 00000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail
41: 00000fb9 36 FUNC GLOBAL DEFAULT 7 _Z43Java_com_android_ralems_GlobalProcess_closeP7_JNIEnvP7_jclassi
42: 0000215c 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Restore_WMMXD
43: 00001189 104 FUNC GLOBAL DEFAULT 7 Java_com_android_ralmes_GlobalProcess_closeGpioM0
44: 00000000 0 FUNC GLOBAL DEFAULT UND write
45: 0000212c 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Restore_VFP
46: 00002230 36 FUNC GLOBAL DEFAULT 7 _Unwind_Resume
47: 00001310 32 FUNC GLOBAL DEFAULT 7 _Unwind_DeleteException
48: 0000130c 4 FUNC GLOBAL DEFAULT 7 _Unwind_Complete
49: 0000aab0 0 NOTYPE GLOBAL DEFAULT ABS __bss_end__
50: 0000109d 236 FUNC GLOBAL DEFAULT 7 Java_com_android_ralmes_GlobalProcess_openSerialPort
51: 0000a93c 0 NOTYPE GLOBAL DEFAULT 11 __INIT_ARRAY__
52: 00000000 0 FUNC GLOBAL DEFAULT UND read
53: 0000238c 888 FUNC GLOBAL DEFAULT 7 __gnu_unwind_execute
54: 0000213c 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Restore_VFP_D
55: 00000000 0 NOTYPE WEAK DEFAULT UND __cxa_type_match
56: 00001d40 108 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Resume
57: 0000214c 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Restore_VFP_D_16_to_31
58: 0000220c 36 FUNC GLOBAL DEFAULT 7 _Unwind_RaiseException
59: 0000aaa0 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
60: 0000aab0 0 NOTYPE GLOBAL DEFAULT ABS __end__
61: 00001c08 28 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_ForcedUnwind
62: 00001d20 32 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Resume_or_Rethrow
63: 00000000 0 FUNC WEAK DEFAULT UND __gnu_Unwind_Find_exidx
64: 00002118 20 FUNC GLOBAL DEFAULT 7 restore_core_regs
65: 000021f8 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Save_WMMXC
66: 00002318 8 FUNC GLOBAL DEFAULT 7 _Unwind_GetTextRelBase
67: 00002328 56 FUNC GLOBAL DEFAULT 7 _Unwind_GetLanguageSpecificData
68: 00001254 76 FUNC GLOBAL DEFAULT 7 _Unwind_VRS_Get
69: 000021e4 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Restore_WMMXC
70: 00002704 64 FUNC GLOBAL DEFAULT 7 __gnu_unwind_frame
71: 00002278 36 FUNC GLOBAL DEFAULT 7 _Unwind_ForcedUnwind
72: 0000aaa0 0 NOTYPE GLOBAL DEFAULT ABS _edata
73: 0000aab0 0 NOTYPE GLOBAL DEFAULT ABS _end
74: 000021a0 0 FUNC GLOBAL DEFAULT 7 __gnu_Unwind_Save_WMMXD
75: 000017cc 8 FUNC WEAK DEFAULT 7 __aeabi_unwind_cpp_pr1
76: 00000000 0 FUNC GLOBAL DEFAULT UND open
77: 00002320 8 FUNC GLOBAL DEFAULT 7 _Unwind_GetDataRelBase
78: 00000000 0 FUNC GLOBAL DEFAULT UND close
我要导出一个叫close的函数,但是第41行的内容如下:
41: 00000fb9 36 FUNC GLOBAL DEFAULT 7 _Z43Java_com_android_ralems_GlobalProcess_closeP7_JNIEnvP7_jclassi
可以看到,导出的函数名不规则,而且ralmes错写成了ralems,
发现问题后立刻就解决了。
解决jni链接时找不到函数的问题的更多相关文章
- ios 引入第三方库 运行时找不到函数实现
今天引入webtrends 这个库,结果一直运行时找不到函数,纳闷了一下午! 后来发现,是other flag没有设置对,对于那些包含category用来扩展ios原始类型的库,链接的时候需要特别的链 ...
- [DNX]解决dnu restore时找不到Newtonsoft.Json的问题
在Mac上用最新版的dnx 1.0.0-beta5-11855进行dnu restore,出现下面的错误: System.IO.FileNotFoundException: Could not loa ...
- ubuntu 下 数学库编译链接时找不到各种数学问题解决方法 can not fon atan 等等
解决参考 http://askubuntu.com/questions/190246/ld-cannot-find-math-library you should use -lm at the end ...
- 解决eclipse配置Tomcat时找不到server选项(Mac通用)
集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在Eclipse中,窗口(window)——首选项(preferences)——服务器(Server)——运行时环境( ...
- 解决远程桌面链接时出现"The RPC server is unavailable."或"RPC服务器不可用"的问题
解决远程桌面链接时出现"The RPC server is unavailable."或"RPC服务器不可用"的问题 解决远程桌面链接时出现"The ...
- 解决eclipse配置Tomcat时找不到server选项
集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在Eclipse中,窗口(window)——首选项(preferences)——服务器(Server)——运行时环境( ...
- 使用SQL Server 2008远程链接时SQL数据库不成功的解决方法
关键设置: 第一步(SQL2005.SQL2008): 开始-->程序-->Microsoft SQL Server 2008(或2005)-->配置工具-->SQL Serv ...
- 在 root 下执行 Oracle 程序时找不到 libclntsh.so.11.1 错误的解决办法。
在 root 下执行 Oracle 程序时找不到 libclntsh.so.11.1 错误的解决办法. 先确定 libclntsh.so.11.1 所在目录: [oracle@localhost ~] ...
- java:解决eclipse配置Tomcat时找不到server选项
http://blog.csdn.net/wugangsunny/article/details/25246565 集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在 ...
随机推荐
- CSS垂直水平居中
小小的总结一下:行内元素水平居中用text-align: center;块级元素水平居中用margin-left: auto; margin-right: auto; 首先讨论一下单行时的情况. 毫无 ...
- android webview点击返回键返回上一级activity
android webview点击返回键返回上一个activity @Override public boolean onKeyDown(int keyCode, KeyEvent event) { ...
- Entity Framework Batch Update
NuGet Package PM> Install-Package EntityFramework.Extended NuGet: http://nuget.org/List/Package ...
- OCP-1Z0-053-V12.02-501题 【转】
http://blog.csdn.net/rlhua/article/details/12225237 501.Note the output of the following query; SQL& ...
- iOS通知NSNotificationCenter
NSNotificationCenter消息通信 作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的. 注册通知:即要在什么地方接受消息 [[NSNotificat ...
- Linux学习之查看是否安装软件
1.rpm包安装的,可以用 rpm -qa 看到,如果要查找某软件包是否安装,用 rpm -qa | grep "软件或者包的名字" 2.以deb包安装的,可以用 dpkg -l ...
- Centos6.5源码编译安装nginx
1.安装pcre下载地址:http://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz #tar -axvf pcre ...
- struts2 日期标签
<td align="center"><s:date name="age" format="yyyy-MM-dd"> ...
- Android Spinner 下拉列表
private Spinner spinner ; private List<String> list ; private ArrayAdapter< ...
- JavaScript装逼指南
如何写JavaScript才能逼格更高呢?怎样才能组织JavaScript才能让别人一眼看出你不简单呢?是否很期待别人在看完你的代码之后感叹一句“原来还可以这样写”呢?下面列出一些在JavaScrip ...