java jni dll路径,JNI:在路径上找到库,但方法不是(java.lang.UnsatisfiedLinkError)

I'm trying to use JNI and getting java.lang.UnsatisfiedLinkError. Unlike the other million questions asked about this, I have the lib on my path, and have even seen the exception change when I remove it. I'm sure that something is wrong with the dll I have created, but I'm not sure what.

Here is my java class code:

package com;

public class Tune {

static {

System.loadLibrary("lala");

}

public static void main(String[] args) {

Tune j = new Tune();

System.out.println("2+6="+j.add(2, 6));

}

native public int add(int x,int y);

}

Here is the abridged portion of my javah produced header file:

/*

* Class: com_Tune

* Method: add

* Signature: (II)I

*/

JNIEXPORT jint JNICALL Java_com_Tune_add

(JNIEnv *, jobject, jint, jint);

Here is my c++ code:

#include

#include

JNIEXPORT jint JNICALL Java_com_Tune_add

(JNIEnv * env, jobject obj, jint x, jint y) {

return x+y;

}

Here is the runtime exception I get from eclipse:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.Tune.add(II)I

at com.Tune.add(Native Method)

at com.Tune.main(Tune.java:9)

I read that the above exception means it DID find the library "lala", but that the method "add" is still not defined. The only things I see different between my project and the tutorial are:

Mine uses a package, instead of the default package (shouldn't tutorials really do this?!?! come on let's get professional)

Mine has a return value.

I moved my dll after it was created (I don't think this will break it since my path is configured.)

How is this possible?

Other Info:

OS: Windows 7

JDK: 1.6.0_31 (for x86, 32 bit jvm)

C++ IDE: Code::Blocks (the dll was compiled automatically by the Code::Blocks IDE)

C++ compiler: MinGW32-g++ (the GNU C++ compiler)

I have jni.h and com_Tune.h in C:\_\include

I have lala.dll in C:\_\lib

Environment Variables:

PATH: C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%CommonProgramFiles%\Microsoft Shared\Windows Live;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Apps;%JAVA_HOME%\bin;C:\Program Files\MySQL\MySQL Server 5.5\bin;%MAVEN_HOME%\bin;%HADOOP_INSTALL%\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\MinGW\bin;C:\Program Files (x86)\GnuWin32\bin;C:_\path;C:\_\lib;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\_\include

解决方案

Just guessing... Is your dll depends on another dll that is not on the path? MinGW modules usually depend on specific C runtime library.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值