linking error ->JNI code

Hi

I am new to JNI.

I am getting linking error as below:

--Configuration: InvokeJava - Win32 Debug--

Compiling...

invoke.c

invoke.obj : error LNK2001: unresolved external symbol __imp__JNI_CreateJavaVM@12

invoke.exe : fatal error LNK1120: 1 unresolved externals

Error executing cl.exe.

InvokeJava.exe - 2 error(s), 0 warning(s)

__

Please help me.

Code is pasted below:

#include<stdlib.h>

#include <jni.h>

#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */

#define USER_CLASSPATH "." /* where Prog.class is */

main() {

JNIEnv *env;

JavaVM *jvm;

jint res;

jclass cls;

jmethodID mid;

jstring jstr;

jclass stringClass;

jobjectArray args;

#ifdef JNI_VERSION_1_2

JavaVMInitArgs vm_args;

JavaVMOption options[1];

options[0].optionString =

"-Djava.class.path=" USER_CLASSPATH;

vm_args.version = 0x00010002;

vm_args.options = options;

vm_args.nOptions = 1;

vm_args.ignoreUnrecognized = JNI_TRUE;

/* Create the Java VM */

res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

#else

JDK1_1InitArgs vm_args;

char classpath[1024];

vm_args.version = 0x00010001;

JNI_GetDefaultJavaVMInitArgs(&vm_args);

/* Append USER_CLASSPATH to the default system class path */

sprintf(classpath, "%s%c%s",

vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);

vm_args.classpath = classpath;

/* Create the Java VM */

res = JNI_CreateJavaVM(&jvm, &env, &vm_args);

#endif /* JNI_VERSION_1_2 */

if (res < 0) {

fprintf(stderr, "Can't create Java VM\n");

exit(1);

}

cls = (*env)->FindClass(env, "Prog");

if (cls == NULL) {

goto destroy;

}

mid = (*env)->GetStaticMethodID(env, cls, "main",

"([Ljava/lang/String;)V");

if (mid == NULL) {

goto destroy;

}

jstr = (*env)->NewStringUTF(env, " from C!");

if (jstr == NULL) {

goto destroy;

}

stringClass = (*env)->FindClass(env, "java/lang/String");

args = (*env)->NewObjectArray(env, 1, stringClass, jstr);

if (args == NULL) {

goto destroy;

}

(*env)->CallStaticVoidMethod(env, cls, mid, args);

destroy:

if ((*env)->ExceptionOccurred(env)) {

(*env)->ExceptionDescribe(env);

}

(*jvm)->DestroyJavaVM(jvm);

}

[2568 byte] By [login1a] at [2007-11-26 20:19:26]
# 1
Hi,you have to link jni.lib with your code. This lib is contained in the lib subdirectory of your JDK. Add jni.lib to the list of libraries and don't forget to add the directory where jni.lib is located to the library search path.Martin
martin@worka at 2007-7-10 0:43:24 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Please call this before creating java VMtypedef jint (JNICALL *CreateJavaVmProc)(JavaVM **pvm, void **env, void *args);Thanks,Sibin.
Shivapa6vathia at 2007-7-10 0:43:24 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
After that useCreateJavaVmProc JNI_CreateJavaVM =(CreateJavaVmProc)::GetProcAddress(path of JVM.dll, "JNI_CreateJavaVM");It will be better than earlierThanks,Sibin.
Shivapa6vathia at 2007-7-10 0:43:24 > top of Java-index,Java HotSpot Virtual Machine,Specifications...