Newbie JNI Question

Hi All,

I'm trying to call one of my java objects from inside an Objective-C method in an application I'm building using XCode.

I'm new to Apple programming so I've been stumpted by a simple problem. In order to get a pointer to the already-running Java VM from inside Objective-C, I'm trying to call the global JNI_GetCreatedJavaVMs. The definition of this function is included in jni.h, and my .m file compiles just fine. But the linker complains that it can't find the library that implements the function.

I have no idea how linking takes place in XCode. Is there someone out there who might be able to walk me through this? I guess the most important question is: where to I find the library?

Mac OS X (10.4.6)





Posted on Jul 8, 2006 6:10 PM

Reply
5 replies

Jul 12, 2006 4:13 PM in response to Patrick Arnesen

Nobody has answered this question yet and I'm still very very stuck. Here's some more information. I'm trying to compile a JNI library as a universal binary (intel & ppc) in XCODE.

Here's the source and the error message:

JNIEnv* getEnv()
{
JavaVM *jvm;
JNIEnv *env;

JNI_GetCreatedJavaVMs(&jvm, 1, NULL);
(*jvm)->AttachCurrentThread(jvm, (void**) &env, NULL);

return env;
}

...

- (void)iconClicked:(id)sender
{
printf("In C, Icon clicked\n");
JNIEnv* env = getEnv();
...
(*env)->CallVoidMethod(env, javaObject, mid);
}

And here's the error message:
Linking /Users/patrickarnesen/MacTaskTrays/build/MacTaskTrays.build/Debug/MacTaskTraysL ib.build/Objects-normal/i386/libMacTaskTraysLib.jnlib (2 errors)

Undefined Symbols

JNIGetCreatedJavaVMs
/Users/patrickarnesen/MacTaskTrays/build/MacTaskTrays.build/Debug/MacTaskTraysLi b.build/Objects-normal/i386/TaskTraysImpl.o reference to undefined JNIGetCreatedVanaVMs

internal link edit command failed


Jul 17, 2006 5:14 PM in response to Patrick Arnesen

Hi Patrick

When I included your getEnv () function in JNI project of mine it appeared to build ok.

I'm no expert on JNI but I think that it's not properly adding the JVM framework to the build. On the main project page, find the Target for your JNI Library, then find the part that links the binary with the libraries. Listed here should be JavaVM.framework. If it is listed then I'd delete it - being careful to delete references NOT files 😉

Now use the finder to go to /System/Library/Frameworks. Find JavaVM.framework and drag to the Link Binary With Libraries phase. When asked, do NOT copy files, just add the framework to the correct target.

If this doesn't fix the problem then I'd refer you to these two technical notes:
http://developer.apple.com/java/jniuniversal.html
http://developer.apple.com/technotes/tn2005/tn2147.html

I would be tempted to create a new Xcode project following the guidelines in the first technical note, dragging file across from the old project.

I really don't know if these suggestions are going to work, but no one else seems to have come up with anything!

Good luck

Bob

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Newbie JNI Question

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.