需要帮助链接到 OS X 上的捆绑包
我是一名经验丰富的 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();
我将 .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_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
所以我的问题是,如何链接到 .jnilib 文件中的代码与 XCode?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要链接到框架,而不是捆绑包。选择“添加现有框架”并选择 JavaVM.framework,Xcode 应该处理其余的事情!
You need to link to frameworks, not bundles. Choose 'Add Existing Framework' and select JavaVM.framework, and Xcode should handle the rest!
我想通了。如果你试图引用存储在 .bundle 中的代码,你实际上并没有链接到它,而是在运行时调用它,然后按名称引用函数(即类似于 Java 的反射,我更喜欢它)熟悉)。
顺便说一句,这对我的目的来说并不是很有用,因为据我所知,java 插件 API 只能从基于 Mozilla 的浏览器调用,而且我正在尝试将 Java 嵌入到我的应用程序中。自己的应用程序。
I figured it out. If you're trying to reference code stored in a .bundle, you don't actually link to it, you make calls to it at runtime and then reference the functions by name (ie. similar to Java's reflection, which I'm more familiar with).
As an aside, this didn't wind up being very useful for my purposes because as far as I can tell, the java plugin API is only designed to be called from Mozilla-based browsers, and I'm trying to embed Java in my own application.