我是一名经验丰富的Java程序员,但我是XCode和C++的新手,所以对于这个愚蠢的问题感到抱歉.
我正在XCode中编写一些需要实例化Java虚拟机的c ++代码.OS X Java插件中有一个名为JavaVM_GetJNIEnv()的方法,以及来自Sun/Oracle的源代码中的头文件,名为JavaVM.h,其中包含以下行:
// 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();
Run Code Online (Sandbox Code Playgroud)
我将.h文件添加到我的XCode项目中,但我不知道如何链接到二进制文件.我想出了如何在链接器中强制加载,如下所示:
-force_load /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/MacOS/JavaPlugin2_NPAPI
Run Code Online (Sandbox Code Playgroud)
(此文件是符号链接;真实路径为/System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/Resources/Java/libplugin2_npapi.jnilib)
但后来我收到此错误消息:
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
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如何使用XCode链接到.jnilib文件中的代码?