Java Library Path - UnsatisfiedLinkError on Mac

从谷歌搜索的结果 复制粘贴一个,用bing 和百度搜索了好久没有搜索到,这么简单的一个问题竟然国内没靠谱的答案,都说是路径设置问题。其实是没有对Mac的平台编译库文件 ,window 用 DLL,Linux 用 SO,Mac eclipse加载,需要编译 dylib库,大多数的工程都是window平台开发,部署到Linux,所以很多人忽略了需要Mac专用的库文件,Linux和Mac还是有差别的。如果你遇到了相同的问题,而且也在Lib里设置了local path,打印出来的路径也没错,那应该就是缺少Mac格式的库文件了。

The problem

I've been trying to run a unit test on my own Mac. The test runs fine on Linux servers, but fails locally with the following trace:

java.lang.UnsatisfiedLinkError: no fedel_client in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    ....

What I've tried

Copy the .so file from the server

I've copied fedel_client.so from the server to /workspace/dapper/java/lib/native/macosx on my local machine, and added it to the java.library.path:

-Djava.library.path=/workspace/dapper/java/lib/native/macosx:...

Create a symlink

I've created a symlink from fedel_clinet to fedel_clinet.so, in case that Java is looking for the former (without the .so extension).

Add the .so directory to .bashrc

I've tried adding .so directory to PATH:

PATH=$PATH:/Users/adamatan/workspaces/trunk/dapper/java/lib/native/macosx

And to LD_LIBRARY_PATH:

export LD_LIBRARY_PATH="/Users/adamatan/workspaces/trunk/dapper/java/lib/native/macosx"

Print the java.library.path

I've printed java.library.path, to see if the changes in the Eclipse environment were propagated to the JVM:

System.out.println(System.getProperty("java.library.path"));

And got:

/workspace/dapper/java/lib/native/macosx:....

The exact values I placed in the Eclipse configuration.

Debugging ideas?

I got the exact same error with all the aforementioned solutions. Any idea how to debug this problem? Can I get a more verbose error message from Java? Is the file not found, or not loaded? If it isn't loaded, why is that?

java eclipse java-native-interface shared-libraries

shareimprove this question

edited Dec 9 '12 at 13:50

asked Dec 9 '12 at 13:34

 

Adam Matan

54.6k102102 gold badges281281 silver badges444444 bronze badges

  • 1

    It should definitely be looking for the library with the .so extension. One question - did you recompile the library for OS X, or just copy the one from linux? If you just copied the linux one, that's probably the problem. – GreyBeardedGeek Dec 9 '12 at 14:26

  • I didn't recompile it, but is there a way to get a more verbose output from java.lang.UnsatisfiedLinkError? – Adam Matan Dec 9 '12 at 14:30

  • @GreyBeardedGeek: no, actually, .so is not the extension of a shared library on Mac OS. – Edward Thomson Dec 9 '12 at 17:10

add a comment

1 Answer

activeoldestvotes

4

 

I may be reading you wrong, but it sounds like you've copied the native library (libfedel_client.so) from the Linux server to your own Mac. If this is the case, this will certainly not work. You cannot use a Linux native library on your Mac, you will need to recompile it on the Mac to produce a libfedel_client.dylib.

Depending on the version of the Apple Java runtime you're using, you may need to use the .jnilibextension. Early runtimes used the .jnilib extension instead of .dylib, and both extensions are still supported (although .dylib is now the default.)

shareimprove this answer

answered Dec 9 '12 at 17:09

Edward Thomson

52.8k1010 gold badges110110 silver badges146146 bronze badges

add a comment

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值