简体   繁体   中英

Another java.lang.UnsatisfiedLinkError with JNI

I have not found a soultion for my problem and was looking since yesterday. I am using Windows 7 and Eclipse with CDT and MinGW.

This is my JAVA class:

package pl.asg.front;

public class ASGFrontMain {
static 
{
    System.loadLibrary("libASG");
}

public native void sayHello();

public static void main(String[] args) {
    System.out.println("Hello from JAVA!");
    new ASGFrontMain().sayHello();
}
}

This is my jni javah generated header file:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class pl_asg_front_ASGFrontMain */

#ifndef _Included_pl_asg_front_ASGFrontMain
#define _Included_pl_asg_front_ASGFrontMain
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     pl_asg_front_ASGFrontMain
 * Method:    sayHello
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_pl_asg_front_ASGFrontMain_sayHello
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

with eclipse external tool thingy: Location: C:\\Program Files (x86)\\Java\\jdk1.7.0_51\\bin\\javah.exe Working directory: ${workspace_loc:/ASG/bin} Arguments: -d ${workspace_loc:/ASG/asg_jni} ${java_type_name}

This is my .cpp implementation:

/*
 * pl_asg_front_ASGFrontMain.c
 *
 *  Created on: 2 kwi 2014
 *      Author: karol
 */

#include "pl_asg_front_ASGFrontMain.h"

JNIEXPORT void JNICALL Java_pl_asg_front_ASGFrontMain_sayHello
  (JNIEnv *env, jobject obj)
{

}

And i am getting this output:

Exception in thread "main" java.lang.UnsatisfiedLinkError: pl.asg.front.ASGFrontMain.sayHello()V
at pl.asg.front.ASGFrontMain.sayHello(Native Method)
Hello from JAVA!
at pl.asg.front.ASGFrontMain.main(ASGFrontMain.java:13)

Any solutions? Thanks in advance.

First, if your native library is called ASG.dll on windows it will be called libASG.so on *nix systems and libASG.dylib on Darwin. Because of this, the library should be loaded by its name, allowing the JVM to populate the correct prefix and extension. Ex: System.loadLibrary("ASG") . Note that OS X uses the wrong extension (.jnilib instead of .dylib) in Java < 7.

Now, you still have an UnsatisfiedLinkError, it is because the JVM has no idea where to load that library from. If you use System.loadLibrary, you must set the property java.library.path to the location of your dll file. Alternatively, you may use System.load() to specify a full path and filename (including prefix and extension) of the native library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM