I am trying to call classes in Java from C++ using jni.h. After some research, I used the following code:
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption* options = new JavaVMOption[1];
options[0].optionString = "-Djava.class.path=/usr/lib/java";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = false;
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
delete options;
jclass cls = env->FindClass("Test.java");
jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V");
env->CallStaticVoidMethod(cls, mid, 100);
jvm->DestroyJavaVM();
However, I am getting 2 errors and they are as follows:
"_JNI_CreateJavaVM", referenced from: _main in main.o"
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone have any input on how to resolve these issues? Thank you very much.
Java version: 1.7.0_71-b14 Java (TM) SE Runtime Environment: (build 1.7.0_71-b14) Java HotSpot(TM) 64-bit Server VM (build 24.71-b01, mixed mode)