未定义的JNI_CreateJavaVM Eclipse和Linux参考

时间:2013-08-19 13:43:14

标签: java-native-interface omnet++

我正在使用Ubuntu 10.04和Omnet ++ 4.0p1以及JSimpleModule(它使用SWIG为Omnet ++中的C ++方法制作Java包装器)。我正在尝试使用上面的2个库在Java中创建模拟,当我尝试构建项目时,我在JUtil.cc(由JSimpleModule提供的代码)中将“未定义的JNI_CreateJavaVM引用”作为错误。我一直在寻找,我包括所有适当的库,它仍然没有修复任何东西。在Omnet ++ IDE(Eclipse)中,我包括:

/usr/lib/jvm/java-6-openjdk/include
/usr/lib/jvm/java-6-openjdk/include/linux
/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client

和我正在联系:

/usr/lib/jvm/java-6-openjdk/jre/lib
/usr/lib/jvm/java-6-openjdk/jre/lib/client
-ljvm

我还尝试使用以下参数使用opp_makemake(创建Makefile)从终端进行编译:

-I/usr/lib/jvm/java-6-openjdk/include
-I/usr/lib/jvm/java-6-openjdk/include/linux
-I/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client
-L/usr/lib/jvm/java-6-openjdk/jre/lib
-L/usr/lib/jvm/java-6-openjdk/jre/lib/client -ljvm

这是JUtil.cc的开头直到错误(注意:jni.h包含在JUtil.h中):

#include "JUtil.h"
#include "JSimpleModule.h"

//#define DEBUGPRINTF printf
#define DEBUGPRINTF (void)

#ifdef _WIN32
#define PATH_SEP ";"
#else
#define PATH_SEP ":"
#endif

// This will come from the generated SimkernelJNI_registerNatives.cc
void SimkernelJNI_registerNatives(JNIEnv *jenv);

JavaVM *JUtil::vm;
JNIEnv *JUtil::jenv;


void JUtil::initJVM()
{
    DEBUGPRINTF("Starting JVM...\n");
    JavaVMInitArgs vm_args;
    JavaVMOption options[10];

    int n = 0;
    const char *classpath = getenv("CLASSPATH");
    if (!classpath)
        opp_error("CLASSPATH environment variable is not set");
    // FIXME remove hack once IDE builds the classpath corretcly
    const char *classpath2 = getenv("CLASSPATH2");
    std::string classpathOption = std::string("-Djava.class.path=")+(classpath2 ? classpath2 : "")+PATH_SEP+(classpath ? classpath : "");
    options[n++].optionString = (char *)classpathOption.c_str(); /* user classes */
    options[n++].optionString = (char *)"-Djava.library.path=."; /* set native library path */
    //options[n++].optionString = "-Djava.compiler=NONE";    /* disable JIT */
    //options[n++].optionString = "-verbose:jni";            /* print JNI-related messages */
    //options[n++].optionString = "-verbose:class";          /* print class loading messages */

    vm_args.version = JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = n;
    vm_args.ignoreUnrecognized = true;

    int res = JNI_CreateJavaVM(&vm, (void **)&jenv, &vm_args);
    if (res<0)
        opp_error("Could not create Java VM: JNI_CreateJavaVM returned %d", res);

    DEBUGPRINTF("Registering native methods...\n");
    SimkernelJNI_registerNatives(jenv);
    DEBUGPRINTF("Done.\n");
}

如果有人知道如何解决这个问题,那将非常感激。感谢。

0 个答案:

没有答案