I'm running on Microsoft Vista using VisualStudio 2008 to create a C++ program that starts a Java process through JNI. I'm using jdk1.6.0_13 which is currently the only JDK on my machine. I started with a very basic program to just boot strap the project, and immediately ran into an issue. I'm linking with the jvm.lib in the JDK lib directory, but I seem to still be missing the import reference for JNI_JavaCreateVM. Any idea why the linker can't pick up the reference?
// Test2JNI.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <jni.h>
int _tmain(int argc, _TCHAR* argv[])
{
JavaVM *jvm = NULL; /* denotes a Java VM */
JNIEnv *env = NULL; /* pointer to native method interface */
JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
JavaVMOption* options = new JavaVMOption[1];
options[0].optionString = "-Djava.class.path=lib/maxwell.jar";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = false;
/* load and initialize a Java VM, return a JNI interface
* pointer in env */
jint result = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
delete[] options;
/* invoke the Main.test method using the JNI */
jclass cls = env->FindClass("com.zenmonics.maxwell.Maxwell");
jmethodID mid = env->GetStaticMethodID(cls, "main", "([Ljava.lang.String)V");
env->CallStaticVoidMethod(cls, mid, 100);
/* We are done. */
jvm->DestroyJavaVM();
return 0;
}
Error
1>------ Build started: Project: Test2JNI, Configuration: Debug Win32 ------
1>Linking...
1>Test2JNI.obj : error LNK2019: unresolved external symbol __imp__JNI_CreateJavaVM@12 referenced in function _wmain
1>C:\Users\Owner\Business\Engagements\Zenmonics\Test2JNI\Debug\Test2JNI.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\Owner\Business\Engagements\Zenmonics\Test2JNI\Debug\BuildLog.htm"
1>Test2JNI - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Link Line =
/OUT:"C:\Users\Owner\Business\Engagements\Zenmonics\Test2JNI\Debug\Test2JNI.exe" /INCREMENTAL /NOLOGO /LIBPATH:"C:\Program Files\Java\jdk1.6.0_13\lib" /MANIFEST /MANIFESTFILE:"Debug\Test2JNI.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\Owner\Business\Engagements\Zenmonics\Test2JNI\Debug\Test2JNI.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT jvm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib