Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: debugging a JNI library: where do I get the JNIEnv

Reply
Thread Tools

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

 
 
lucky
Guest
Posts: n/a
 
      04-02-2004
Chris Uppal <(E-Mail Removed)-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?
 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      04-02-2004
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


 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      04-07-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
call jni function dynamically without getting a JNIEnv handle as anargument. junyoung Java 1 04-27-2010 09:01 AM
JNIEnv * DGG Java 2 05-23-2007 11:52 AM
Using JNIEnv In Native Method cppaddict Java 3 07-21-2004 12:14 AM
Porting JNI Windows under JNI LINUX + Wine ? Pasturel Jean-Louis Java 5 03-03-2004 07:50 PM
IBM's JNI fails where Sun's JNI works Alex Hunsley Java 4 11-04-2003 10:34 AM



Advertisments