0

I am using Ubuntu 10.04 with Omnet++ 4.0p1 and JSimpleModule (which uses SWIG to make Java wrappers for the C++ methods found in Omnet++). I am trying to create a simulation in Java using the 2 above libraries, and when I am trying to build the project I am getting 'Undefined Reference to JNI_CreateJavaVM' as an error in JUtil.cc (which is code supplied by JSimpleModule). I have been looking around and I am including all of the proper libraries and it still isn't fixing anything. In the Omnet++ IDE (Eclipse) I am including:

/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

and am linking:

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

I also tried compiling from the terminal using opp_makemake (which creates a Makefile) with the following parameters:

-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

Here is the beginning of JUtil.cc up to the error (note: jni.h is included in 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");
}

If someone knows anything on how to fix this, that would be greatly appreciated. Thanks.

  • Have you mentioned `jvm` static lib file in your project? – nabroyan Aug 19 '13 at 13:57
  • I'm not sure, what is the jvm static lib file name? If it is libjvm.so, then yes. – user2049080 Aug 19 '13 at 14:41
  • Please take look to this http://stackoverflow.com/questions/9923495/undefined-reference-shm-open-already-add-lrt-flag-here/9923523#9923523;http://stackoverflow.com/questions/16860021/undefined-reference-to-jni-createjavavm-linux;http://stackoverflow.com/questions/17070879/jni-java-to-c-in-eclipse-undefined-reference-to-imp-jni-createjavavm12 – nabroyan Aug 19 '13 at 19:28
  • http://stackoverflow.com/questions/16860021/undefined-reference-to-jni-createjavavm-linux – nabroyan Aug 19 '13 at 19:29
  • In both of those links, it says to put `-ljvm` after the file that uses that library. But if I am compiling in Eclipse, how would I do that? – user2049080 Aug 20 '13 at 13:21
  • I think you should do that in your project dependency list. – nabroyan Aug 20 '13 at 13:39
  • Ya I did, I showed that in my question, but is that right? I went to Project>Properties>Library Paths and added it at the end of the list – user2049080 Aug 20 '13 at 14:18
  • I think you should add file's extension – nabroyan Aug 20 '13 at 14:54
  • I mean extension of `client` – nabroyan Aug 20 '13 at 18:15
  • Okay, I added changed it to `-L/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client/libjvm.so -ljvm` and I am still getting the error – user2049080 Aug 21 '13 at 12:09

0 Answers0