Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要帮助链接到OS X上的捆绑包吗 我是一个有经验的java程序员,但我对XCODE和C++很陌生,很抱歉,这个问题很愚蠢。 我在XCODE中编写了一些C++代码,需要实例化java虚拟机。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();_Xcode_Cocoa_Macos_Linker_Bundle - Fatal编程技术网

需要帮助链接到OS X上的捆绑包吗 我是一个有经验的java程序员,但我对XCODE和C++很陌生,很抱歉,这个问题很愚蠢。 我在XCODE中编写了一些C++代码,需要实例化java虚拟机。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();

需要帮助链接到OS X上的捆绑包吗 我是一个有经验的java程序员,但我对XCODE和C++很陌生,很抱歉,这个问题很愚蠢。 我在XCODE中编写了一些C++代码,需要实例化java虚拟机。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();,xcode,cocoa,macos,linker,bundle,Xcode,Cocoa,Macos,Linker,Bundle,我将.h文件添加到我的XCode项目中,但我不知道如何链接到二进制文件。我想出了如何在链接器中强制加载,如下所示: -force_load /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/MacOS/JavaPlugin2_NPAPI (该文件是一个符号链接;实际路径是/System/Library/Java/Support/Deploy.bundle

我将.h文件添加到我的XCode项目中,但我不知道如何链接到二进制文件。我想出了如何在链接器中强制加载,如下所示:

-force_load /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin/Contents/MacOS/JavaPlugin2_NPAPI
(该文件是一个符号链接;实际路径是/System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2\u NPAPI.plugin/Contents/Resources/Java/libplugin2\u 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

所以我的问题是,如何使用XCode链接到.jnilib文件中的代码?

您需要链接到框架,而不是捆绑包。选择“addexistingframework”并选择JavaVM.Framework,剩下的就由Xcode来处理了

我明白了。如果您试图引用存储在.bundle中的代码,您实际上并没有链接到它,而是在运行时调用它,然后按名称引用函数(例如,类似于我更熟悉的Java反射)


顺便说一句,这对我来说并不是很有用,因为据我所知,java插件API只设计用于从基于Mozilla的浏览器调用,我正在尝试将java嵌入到我自己的应用程序中。

我的框架列表中已经有了JavaVM.framework。。。可能该函数是在不同的库中定义的。我将使用“nm”进行搜索,以确定哪个二进制文件具有我要查找的函数;也许我只需要添加一个不同的框架。好的,我找到了文件的真实位置。我使用“nm”来验证我需要的函数是否包含在内。实际二进制文件上的位置是“/System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2\u NPAPI.plugin/Contents/MacOS/JavaPlugin2\u NPAPI”。既然我不能向XCode添加bundle,我该如何链接到它呢?在osx下,gcc包装器接受-F和-framework作为参数-F/-framework类似于-L/-L,但我认为sbooth是正确的-如果它没有正确链接,那么有些东西是不可靠的。您试图链接到的东西是web浏览器Java插件的一部分(因此路径中的NPAPI)。你确定这就是你想要的吗?
NPError (*getEntryPoints)(NPPluginFuncs *aNPPFuncs); //Defines a variable which is a pointer to a function

CFURLRef bundleUrl = CFURLCreateWithFileSystemPath(NULL, CFSTR("/System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin"), kCFURLPOSIXPathStyle, true);
CFBundleRef bundleRef = CFBundleCreate(NULL, bundleUrl);
getEntryPoints = (NPError (*)(NPPluginFuncs *))CFBundleGetFunctionPointerForName ( bundleRef, CFSTR("NP_GetEntryPoints" ) ); //Sets the pointer function to a function loaded from the bundle

if( getEntryPoints == NULL ) {
    printf("getEntryPoints is NULL");
} else {
    NPPluginFuncs pluginFuncs;
    pluginFuncs.size = sizeof(NPPluginFuncs);

    NPError err = getEntryPoints( &pluginFuncs ); //This is what actually calls the library function
    //... do more stuff with plugin API ...
}