用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链接时找不到函数的问题的更多相关文章

  1. ios 引入第三方库 运行时找不到函数实现

    今天引入webtrends 这个库,结果一直运行时找不到函数,纳闷了一下午! 后来发现,是other flag没有设置对,对于那些包含category用来扩展ios原始类型的库,链接的时候需要特别的链 ...

  2. [DNX]解决dnu restore时找不到Newtonsoft.Json的问题

    在Mac上用最新版的dnx 1.0.0-beta5-11855进行dnu restore,出现下面的错误: System.IO.FileNotFoundException: Could not loa ...

  3. ubuntu 下 数学库编译链接时找不到各种数学问题解决方法 can not fon atan 等等

    解决参考 http://askubuntu.com/questions/190246/ld-cannot-find-math-library you should use -lm at the end ...

  4. 解决eclipse配置Tomcat时找不到server选项(Mac通用)

    集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在Eclipse中,窗口(window)——首选项(preferences)——服务器(Server)——运行时环境( ...

  5. 解决远程桌面链接时出现"The RPC server is unavailable."或"RPC服务器不可用"的问题

    解决远程桌面链接时出现"The RPC server is unavailable."或"RPC服务器不可用"的问题 解决远程桌面链接时出现"The ...

  6. 解决eclipse配置Tomcat时找不到server选项

    集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在Eclipse中,窗口(window)——首选项(preferences)——服务器(Server)——运行时环境( ...

  7. 使用SQL Server 2008远程链接时SQL数据库不成功的解决方法

    关键设置: 第一步(SQL2005.SQL2008): 开始-->程序-->Microsoft SQL Server 2008(或2005)-->配置工具-->SQL Serv ...

  8. 在 root 下执行 Oracle 程序时找不到 libclntsh.so.11.1 错误的解决办法。

    在 root 下执行 Oracle 程序时找不到 libclntsh.so.11.1 错误的解决办法. 先确定 libclntsh.so.11.1 所在目录: [oracle@localhost ~] ...

  9. java:解决eclipse配置Tomcat时找不到server选项

    http://blog.csdn.net/wugangsunny/article/details/25246565 集成Eclipse和Tomcat时找不到server选项: 按照网上的步骤如下: 在 ...

随机推荐

  1. DQL

    DQL(Data QueryLanguage) 基本格式 select * from 表名 对于列进行限制 格式一:取指定列 select 列1,列2 from 表名 格式二:为列起别名的三种表示法, ...

  2. node.js(七) 子进程 child_process模块

    众所周知node.js是基于单线程模型架构,这样的设计可以带来高效的CPU利用率,但是无法却利用多个核心的CPU,为了解决这个问题,node.js提供了child_process模块,通过多进程来实现 ...

  3. Js 自定义回调函数

    参考 http://mlxnle.iteye.com/blog/1670679 <!doctype html> <html lang="es"> <h ...

  4. TCP/IP的三次握手协议

    关于TCP/IP的三次握手协议,这篇文章中有详细的介绍,很通俗易懂,什么时候忘了,都可以过来瞧两眼,保证很快就明白了. 首先TCP/IP协议分为三个阶段:建立连接(握手阶段),数据传输阶段,连接终止阶 ...

  5. 浅谈C中的指针和数组(三)

    上一个博客我们得到了一个结论: 指针和数组根本就是两个完全不一样的东西.只是它们都可以“以指针形式”或“以下标形式”进行访问.一个是完全的匿名访问,一个是典型的具名+匿名访问.一定要注意的是这个“以X ...

  6. leetcode Remove Element python

    class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] ...

  7. Matlab图像直方图相关函数

    图像的灰度直方图(H是图像a.bmp的数据矩阵) imhist(H):%显示a的直方图 histeq(H); %将图像a进行直方图均衡化 adapthisteq(H); %将图像a进行直方图均衡化 i ...

  8. jmeter实例演示

    Jmeter 是比较轻便的性能测试工具,下面根据一个实例演示下jmeter的常见用法 一.前期准备,在使用之前,先分析测试需求,比如:需不要登录?需不需要监视服务器性能?多线程还是多循环?需不需根据流 ...

  9. SQL Server 触发器的修改与删除

    修改: alter trigger trigger_name on ..... as .....   #把create 修成  alter 就可以了. 删除: drop trigger trigger ...

  10. 如何使用win7自带的备份还原以及创建系统镜像------傻瓜式教程

    对于经常鼓捣电脑的童鞋来说,装系统是一件极其平常的事情,不过系统装多了之后,我们会感到比较烦躁,因为每一次装系统意味着驱动的重新安装,程序的重新安装,每次这么鼓捣几次,半天时间就花在这上面了,效率是在 ...