体系结构x86_64的未定义符号:JNI_CreateJavaVM OS-X Xcode [英] Undefined symbols for architecture x86_64: JNI_CreateJavaVM OS-X Xcode

查看:157
本文介绍了体系结构x86_64的未定义符号:JNI_CreateJavaVM OS-X Xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OS-X Mountain Lion上使用Xcode编译以下C ++代码以创建Java虚拟机:

I am attempting to compile the following C++ code for creating a Java Virtual Machine, using Xcode on Mac OS-X Mountain Lion:

JNIEnv * createVM(JavaVM **jvm){
    JNIEnv * retEnv = NULL;
    JavaVMInitArgs vm_args = *new JavaVMInitArgs();
    JavaVMOption *options = new JavaVMOption[1];

    std::string sJavaInstallPath = "-Djava.class.path=" + findJavaPath();

    if(sJavaInstallPath == "-Djava.class.path="){
        return NULL;
    }

    options[0].optionString = const_cast<char*>(sJavaInstallPath.c_str());
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = false;

    long status = JNI_CreateJavaVM(jvm, (void**)&retEnv, &vm_args);

    if(status == JNI_ERR){
        std::cout << "Failure: Unable to load JVM \t Exit" << std::endl;
    }else if(status == JNI_OK){
        std::cout << "CreateVM:\t\tJVM loaded successfully" << std::endl;
    }

    delete options;
    return retEnv;
};

哪个出现以下错误: x86_64体系结构的未定义符号:"_ JNI_CreateJavaVM".

Which gives the following error: Undefined symbols for architecture x86_64: "_JNI_CreateJavaVM".

从这些类似的问题中

对"JNI_CreateJavaVM" linux的未定义引用

如何使用JNI在C ++中使用Java类?

未定义符号:Linux中的JNI_CreateJavaVM

http://lists.apple.com/archives/java-dev/2005 /Apr/msg00067.html

http://lists.apple.com/archives/java-dev/2005 /Apr/msg00068.html

我发现我缺少对libjvm.dylib的库引用.问题是我不确定如何使Xcode识别/包括用于链接的库,

I gather that I'm missing a Library reference to libjvm.dylib. The problem is that I'm not sure how to get Xcode to recognize/include the library for linking,

我尝试将以下目录(所有目录都包含一个libjvm.dylib文件)放入Xcode的库搜索路径"列表中,但没有结果:

I've tried putting the following directories (all of which contain a libjvm.dylib file) into the Library Search Paths list in Xcode, with no result:

/System/Library//Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/

/System/Library//Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/

/Library//Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/server/

/Library//Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/server/

/System/Library/Frameworks/JavaVM.framework/Libraries/

/System/Library/Frameworks/JavaVM.framework/Libraries/

我对OS-X和Xcode还是很陌生,其他问题的答案都与我使用gcc或g ++的经验有关,所以我需要知道的是:如何做我告诉Xcode编译器在哪里可以找到libjvm.dylib,还有我应该链接到的libjvm.dylib?

I'm still quite new to OS-X and Xcode, and the answers to the other questions all relate to compiling using gcc or g++, which I have even less experience with, so what I need to know is: how do I tell the Xcode compiler where to find libjvm.dylib, and also which libjvm.dylib is the one I should be linking to?

推荐答案

确定,找到了解决方案,

OK, found the solution,

相当于g ++的

-L<library/to/link>

Xcode中的

设置是 Build Phases 标签下的 Link Binary with Libraries 设置, 不是我上面提到的图书馆搜索路径"列表.

setting in Xcode is the Link Binary with Libraries setting under the Build Phases tab, not the Library Search Paths list that I mentioned above.

我需要链接的库实际上是/System/Library/Frameworks/JavaVM.framework/JavaVM

and the library I needed to link to was actually /System/Library/Frameworks/JavaVM.framework/JavaVM,

不是libjvm.dylib

not libjvm.dylib

这篇关于体系结构x86_64的未定义符号:JNI_CreateJavaVM OS-X Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆