1
votes
JNIEXPORT jint JNICALL JNI_Func(....) {
  ....
}

I get unsatisfied link error when i try to run the java program with macros (JNIEXPORT and JNICALL) in the native code. But when i remove the macros,i get no exception. Is it that the IDE Code::Blocks doesn't support JNI macros ? If it supports what should i do to enable them ?

Note : I don't get a error or warning related to the macros defined . It just fails the run,as it gives me the unsatisfied link error.

EDIT :

Stacktrace :

Exception in thread "main" java.lang.UnsatisfiedLinkError:  keylogger.TestKeys.initializeJNIVars()V
    at keylogger.TestKeys.initializeJNIVars(Native Method)
    at keylogger.TestKeys.main(TestKeys.java:22)

But before throwing this exception,it prints a line from the native code. The problem is really the macros.

1
The mascros are required to satisfy the JNI linkage. Whatever the problem is, the solution cannot involve removing them. - user207421

1 Answers

1
votes

If the source compiles and the DLL is created, then there is nothing wrong with Code::Blocks. Code::Blocks uses gcc, and gcc can create JNI DLLs with no problem

If you getting this error when you are running the Java class, then make sure you have placed the DLL inside the java.library.path

Edit

You need to add these two options on Project->Build options->Linker Settings->Other Linker Options to make it work:

-Xlinker --add-stdcall-alias