Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help linking to bundle on OS X

I'm an experienced Java coder, but I'm new to XCode and C++, so sorry for the dumb question.

I'm writing some c++ code in XCode that needs to instantiate a Java Virtual Machine. There is a method in the OS X Java plugin called JavaVM_GetJNIEnv(), and a header file in the source code from Sun/Oracle called JavaVM.h with these lines:

// Gets the JNIEnv* associated with the Java VM, creating the JVM
// instance if necessary. Note that the implementation of this routine
// must be prepared for it to be called from more than one thread.
JNIEnv* JavaVM_GetJNIEnv();

I added the .h file to my XCode project, but I don't know how to link to the binary file. I figured out how to force-load in the linker, like this:

-force_load /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/MacOS/JavaPlugin2_NPAPI

(this file is a symbolic link; the real path is /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/Resources/Java/libplugin2_npapi.jnilib)

But then I get this error message:

ld: in /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/MacOS/JavaPlugin2_NPAPI, can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB)
collect2: ld returned 1 exit status

So my question is, how do I link to code in a .jnilib file with XCode?

like image 211
Jesse Barnum Avatar asked Oct 10 '22 13:10

Jesse Barnum


1 Answers

You need to link to frameworks, not bundles. Choose 'Add Existing Framework' and select JavaVM.framework, and Xcode should handle the rest!

like image 167
sbooth Avatar answered Oct 22 '22 10:10

sbooth