Error in creating JVM, need help!
I am just trying a simple c program to create a JVM on a linux machine. However it always result errors during compilation. I got no idea what's went wrong.
I am using jdk1.2.
#include <jni.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
jint res;
vm_args.version=0x00010001;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
vm_args.classpath=".:/usr/local/jdk1.2.2/include/linux/jni_md.h:/usr/local/jdk1.2.2/include$
JNI_GetDefaultJavaVMInitArgs(&vm_args);
res=JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
(*jvm)->DestroyJavaVM(jvm);
return(0);
}
Errors:
/tmp/ccvMj208.o: In function `main':
/home/bettylo/2/invoke.c:12: undefined reference to `JNI_GetDefaultJavaVMInitArgs'
/home/bettylo/2/invoke.c:14: undefined reference to `JNI_GetDefaultJavaVMInitArgs'
/home/bettylo/2/invoke.c:15: undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status
--
This is the command I use to compile the c program
gcc -I$JAVA_HOME/include/linux -I$JAVA_HOME/include -o invoke.exe invoke.c
You can set the LD_LIBRARY_PATH in linux with the follow command :
Replace whatever specific library path you need in the below example!
Red Hat Linux specific format :
export LD_LIBRARY_PATH=<your lib path>:<other paths required>:$LD_LIBRARY_PATH
Another small example :
export LD_LIBRARY_PATH=/usr/java/jsdk1.2/jre/lib:$LD_LIBRARY_PATH
Only after loading the library environment will you be able to run the JVM successfully.
Your other question on the segmentation core dump is probably due to the fact that you use a (void**) pointer with the old 1.1 vm_args.version. JDK versions lower than 1.2 uses the older interface that is not as portable and takes a JNIEnv pointer in the
JNI_CreateJavaVM(JavaVM* ,JNIEnv **,JDK1_1InitArgs);
method but newer 1.2 uses
JNI_CreateJavaVM(JavaVM* ,void **,JavaVMInitArgs);
Read the updated docs on 1.2 from your JDK distribution and you will realize that the segmentation crush was due to pointer problems. Note also that the code to invoke the 1.2 version and 1.1 versions are different, so read the docs carefully.
Hi,
I am using the example ie in chap7 of http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html ie invoke.c ..
In invoke.c program we are loading jvm for calling java methods in this c program..
while compiling the using the you specified command ie
cc-I/usr/java2/include -I/usr/java2/include/unixware -L/usr/java2/jre/lib/x86at -o invoke invoke.c
i am getting the errors like
belowUndefinedfirst referenced
symbolin file
JNI_CreateJavaVMinvoke.o
UX:ld: ERROR: invoke: fatal error: Symbol referencing errors. No output written
to invoke
tell me how to run and execute the this c function
pls send to gali123@hotmail.com
it's very Urgent to us..
Thanks
GaliS at 2007-6-29 10:23:50 >
