File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes JNI : undefined reference to JNI_CreateJavaVM() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JNI : undefined reference to JNI_CreateJavaVM()" Watch "JNI : undefined reference to JNI_CreateJavaVM()" New topic

JNI : undefined reference to JNI_CreateJavaVM()

Abhishek Chaudhari

Joined: Feb 09, 2005
Posts: 11
I'm trying to work on the JNI invocation APIs.

Platform : Windows XP Professional
JDK : j2sdk1.4.2
C-Compiler : MinGW's gcc.

1.The invoke.c file as follows:

#include <jni.h>

#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else /* UNIX */
#define PATH_SEPARATOR ':'

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

main() {
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs vm_args;
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jobjectArray args;
char classpath[1024];

/* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
vm_args.version = 0x00010001;

// JNI_GetDefaultJavaVMInitArgs(&vm_args);

/* Append USER_CLASSPATH to the end of default system class path */
sprintf(classpath, "%s%c%s",
vm_args.classpath = classpath;

/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");

cls = (*env)->FindClass(env, "Prog");
if (cls == 0) {
fprintf(stderr, "Can't find Prog class\n");

mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String V");
if (mid == 0) {
fprintf(stderr, "Can't find Prog.main\n");

jstr = (*env)->NewStringUTF(env, " from C!");
if (jstr == 0) {
fprintf(stderr, "Out of memory\n");
args = (*env)->NewObjectArray(env, 1,
(*env)->FindClass(env, "java/lang/String"), jstr);
if (args == 0) {
fprintf(stderr, "Out of memory\n");
(*env)->CallStaticVoidMethod(env, cls, mid, args);


2. The file :

public class Prog
public static void main(String[] args)
System.out.println("Hello World" + args[0]);

3. On compiling invoke.c using

gcc -D_JNI_IMPLEMENTATION_ -IC:\j2sdk1.4.2\include -IC:\j2sdk1.4.2\include\win32 invoke.c

I'm getting following error.
invoke.c: undefined reference to `JNI_GetDefaultJavaVMInitArgs@4'
invoke.c: undefined reference to `JNI_CreateJavaVM@12'

Can anybody please help me out with this?
Consider Paul's rocket mass heater.
subject: JNI : undefined reference to JNI_CreateJavaVM()
It's not a secret anymore!