解决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选项: 按照网上的步骤如下: 在 ...
随机推荐
- MVC中使用AuthorizeAttribute做身份验证操作【转】
http://blog.csdn.net/try530/article/details/7782704 代码顺序为:OnAuthorization-->AuthorizeCore-->Ha ...
- ASP.NET mvc4 WEB API异常处理
当一个web api抛出一个异常后 此异常会被转化成一个HTTP响应 错误代码为500的服务错误 但是如果你不想让客户端看到500的错误码 你也可以自定义错误码 如下代码当用户输入的ID没有与之相关的 ...
- Asp.Net之三层架构
三层架构之理论: 通常意义上讲的三层架构就是将整个项目应用划分为:表现层(UI),业务逻辑层(BLL),数据访问层(DAL).与传统的二层架构的区别在于在用户界面(UI)和数据库服务器之间,添加中间层 ...
- Nodejs随笔(一):Hello World!
声明:本人用的是Ubuntu 14.04 LTS 系统. 一.Nodejs安装: <1>直接apt-get安装,最简单:sudo apt-get install nodejs <2& ...
- 创建SDE表空间
创建空间数据存储类型为ST_Geometry的要素类有2种方法:1)使用SDE创建要素类从9.3 开始,默认创建的要素类都使用ST_Geometry存储空间数据,9.3 版本之前,可以通过配置dbtu ...
- QF——iOS通知中心(NotificationCener)
前面我们讲iOS不同界面间传值的时候,说过可以通过通知中心进行传值.那到底什么是通知中心,他是如何实现传值的呢? NSNotificationCenter是单例的,只提供了一个唯一的实例化入口,在整个 ...
- 关于 MyBatis MyBatis-Spring Jdbc 批量插入的各种比较分析
因为目前SME项目中编写了一套蜘蛛爬虫程序,所以导致插入数据库的数据量剧增.就项目中使用到的3种DB插入方式进行了一个Demo分析: 具体代码如下: 1: MyBatis 开启Batch方式,最普通的 ...
- hdu 4676 Sum Of Gcd 莫队+数论
题目链接 给n个数, m个询问, 每个询问给出[l, r], 问你对于任意i, j.gcd(a[i], a[j]) L <= i < j <= R的和. 假设两个数的公约数有b1, ...
- larbin源码之global.h
/** This represent a connection : we have a fixed number of them * fetchOpen links them with servers ...
- LINUX常用命令--基础篇(一)
1. man 对你熟悉或不熟悉的命令提供帮助解释 eg:man ls 就可以查看ls相关的用法 注:按q键或者ctrl+c退出,在linux下可以使用ctrl+c终止当前程序运行. 2. ls 查看目 ...