Re: debugging a JNI library: where do I get the JNIEnv

Discussion in 'Java' started by lucky, Apr 2, 2004.

  1. lucky

    lucky Guest

    Chris Uppal <-THIS.org> wrote in message

    > JavaVMOption options[2] = { { "-verbose:jni" } , { "-Xcheck:jni" } };
    > JavaVMInitArgs initArgs;
    > initArgs.version = JNI_VERSION_1_2;
    > initArgs.nOptions = 2;
    > initArgs.options = options;
    > initArgs.ignoreUnrecognized = true;
    > JNIEnv *jniEnv;
    > JavaVM *javaVM;
    > createJavaVM(&javaVM, (void**)&jniEnv, &initArgs);


    Thank you Chris,

    This should indeed be the way it is done, as I also see in the Sun
    Tutorials.
    I try this however, and first the compiler does not find the
    libjvm.so.

    Solution (I think) I copy this file from
    /usr/java/j2sdk1.4.2_03/jre/lib/i386/client directory to the test dir
    and I do a ldconfig . Note: the JAVA_HOME is /usr/java/j2sdk1.4.2_03

    Then I recompile and run the program, the program crashes however at
    the createJavaVM (Segmentation Fault) It is the same with your code,
    or with the code from the JNI Invocation sample from Sun.

    What do I do wrong here?
    lucky, Apr 2, 2004
    #1
    1. Advertising

  2. lucky

    Chris Uppal Guest

    lucky wrote:

    > Solution (I think) I copy this file from
    > /usr/java/j2sdk1.4.2_03/jre/lib/i386/client directory to the test dir
    > and I do a ldconfig . Note: the JAVA_HOME is /usr/java/j2sdk1.4.2_03
    >
    > Then I recompile and run the program, the program crashes however at
    > the createJavaVM (Segmentation Fault) It is the same with your code,
    > or with the code from the JNI Invocation sample from Sun.


    I'm sorry, but I don't know.

    It's a few years since last did C programming on *NIX, and I've never mixed JNI
    with *NIX.

    Hopefully someone else will chip in.

    -- chris
    Chris Uppal, Apr 2, 2004
    #2
    1. Advertising

  3. On 2 Apr 2004 03:40:33 -0800, lucky wrote:
    > I try this however, and first the compiler does not find the
    > libjvm.so.
    >
    > Solution (I think) I copy this file from
    > /usr/java/j2sdk1.4.2_03/jre/lib/i386/client directory to the test dir
    > and I do a ldconfig . Note: the JAVA_HOME is /usr/java/j2sdk1.4.2_03


    Don't move the libraries!

    The solution is to tell the compiler where to find them. Use -L for
    each directory, e.g.:

    gcc -D_REENTRANT -I $JAVA_HOME/include -I $JAVA_HOME/include/linux \
    -L $JAVA_HOME/jre/lib/i386 -L $JAVA_HOME/jre/lib/i386/client \
    launcher.c -ljvm -lpthread -o launcher

    (all one line)

    The launcher will also need to find the libraries at runtime. You can
    do that by adding the two directories to your LD_LIBRARY_PATH, or by
    telling the linker to include the information in the executable itself
    by adding the following flags to the above command line:

    -Wl,-R$JAVA_HOME/jre/lib/i386
    -Wl,-R$JAVA_HOME/jre/lib/i386/client

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Apr 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    839
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    894
    Pasturel Jean-Louis
    Mar 3, 2004
  3. cppaddict

    Using JNIEnv In Native Method

    cppaddict, Jul 20, 2004, in forum: Java
    Replies:
    3
    Views:
    15,670
    cppaddict
    Jul 21, 2004
  4. DGG

    JNIEnv *

    DGG, May 22, 2007, in forum: Java
    Replies:
    2
    Views:
    808
    Thomas Fritsch
    May 23, 2007
  5. junyoung
    Replies:
    1
    Views:
    989
Loading...

Share This Page