Reputation: 41
I have been trying to create a simple JNI Test with C++. For Java I am using Eclipse, and for C++ I am using Visual Studio 2013. I followed the directions on other pages on StackOverFlow but nothing really seems to work. The error occurs when I try calling the native method in java listed in C++.
Thanks for your time.
#include <jni.h>;
using namespace std;
#ifndef Header
#define Header
JNIEXPORT void JNICALL Java_base_Main_print(JNIEnv *env, jobject obj);
#endif
#include <jni.h>;
using namespace std;
#ifndef Header
#define Header
extern "C" {
JNIEXPORT void JNICALL Java_base_Main_print(JNIEnv *env, jobject obj);
}
#endif
#include "Header.h";
JNIEXPORT void JNICALL Java_base_Main_print(JNIEnv *env, jobject obj) {
printf("This is a JNI tester\n");
//return;
}
package base;
public class Main {
static {System.loadLibrary("JNIHelloWorld");}
public static void main(String args[]){
Main m = new Main();
m.print();
}
public native void print();
}
Exception in thread "main" java.lang.UnsatisfiedLinkError: base.Main.print()V
at base.Main.print(Native Method)
at base.Main.main(Main.java:9)
Upvotes: 2
Views: 1248
Reputation: 1488
try #extern "c" { } around the JNI code.
Verify by looking at the exports of your DLL to see that the C++ name mangling did not get involved.
Upvotes: 3