0

I don't know why is giving me errors on JNIEXPORT and JNICALL...

Info: Visual studio 2017, Windows

JAVA_HOME is set.

Added the directory in 'C/C++ > General > Additional Include Directories'

Include directory > C:\Program Files\Java\jdk1.8.0_251\include

I tried adding jvm.lib but didn't work.

error: JNIERROR - 'variable JNIEXPORT is not type name' JNICALL - 'Expected ;'

code:

#include <iostream>
#include <jvmti.h>
#include <jni.h>


JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {

}
  • with the includes you have *JNIEXPORT* (and probably *JNICALL*) is not known (as a pre-processor variable very probably) so the compiler consider it as type. `JAVA_HOME is set.` not relevant for your C++ compiler – bruno Jul 29 '20 at 12:55
  • may be as in https://stackoverflow.com/questions/11561216/type-jnicall-could-not-be-resolved just define them as an empty preprocessor definition ... supposing you cannot just remove them to have `jint Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {}` – bruno Jul 29 '20 at 12:59
  • Please check that you are including the correct jni.h file (from your JDK) and that it contains these definitions. – Botje Jul 29 '20 at 13:06
  • "jni.h" can't possibly be included correctly, if the include directories have only "...\jdk\include". "jni.h" pulls "jni_md.h" and that is in "...\jdk\include\win32" on Windows. – user2543253 Jul 29 '20 at 13:39
  • i will check everyone proposals and give feedback later! – Jonathan Smith Jul 29 '20 at 17:40
  • ok for some reason after adding C:\Program Files\Java\jdk1.8.0_251\include\win32 it worked. thanks everyone for the effort. – Jonathan Smith Jul 29 '20 at 18:25
  • Going to make this into an answer, to have one less unanswered question. – user2543253 Jul 31 '20 at 11:22

1 Answers1

0

When you include "jni.h" to compile JNI code in C or C++ you have to add both your JDK's "include" directory to your include path and the directory where the platform dependent include files (referenced by "jni.h") are. Those are "include\win32" on Windows, "include/linux" on Linux, and "include/darwin" on macOS. Usually a compiler will output a message if an include file is not found, so pay attention to all messages, not only the last one.

user2543253
  • 2,143
  • 19
  • 20