Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Under Linux, Call java from C++

Reply
Thread Tools

Under Linux, Call java from C++

 
 
tony_lincoln@yahoo.com
Guest
Posts: n/a
 
      09-30-2005
I set the path like this:

export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jvm/java-1.4.2-sun-1.4.2.05/jre/lib/i386/server/

This time I can compile it and got invoke.o and invoke. But when I type
invoke
then the new information comes:
Can't create Java VM

I really wonder why?

 
Reply With Quote
 
 
 
 
tony_lincoln@yahoo.com
Guest
Posts: n/a
 
      09-30-2005
I found two libjvm.so.
/usr/lib/jvm/java-1.4.2-sun-1.4.2.05/jre/lib/i386/client/libjvm.so
/usr/lib/jvm/java-1.4.2-sun-1.4.2.05/jre/lib/i386/server/libjvm.so
I know that they are different. But what is the difference?

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      09-30-2005
On 30 Sep 2005 08:52:19 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I set the path like this:
>
> export
> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jvm/java-1.4.2-sun-1.4.2.05/jre/lib/i386/server/
>
> This time I can compile it and got invoke.o and invoke. But when I type
> invoke
> then the new information comes:
> Can't create Java VM
>
> I really wonder why?


You need to add *two* directories to LD_LIBRARY_PATH:

/usr/lib/jvm/java-1.4.2-sun-1.4.2_05/jre/lib/i386/server
/usr/lib/jvm/java-1.4.2-sun-1.4.2_05/jre/lib/i386

/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
 
tony_lincoln@yahoo.com
Guest
Posts: n/a
 
      09-30-2005
You are right. My java version is 1.4.2_05.
So I changed the codes into
vm_args.version = JNI_VERSION_1_4_2_05;

But the error kept the same:

rakta:~/GAQ$ gcc -Wall -D_REENTRANT -I
/home/gao/java/j2sdk1.4.2_08/include -I
/home/gao/java/j2sdk1.4.2_08/include/linux-c invokeLinux.cpp
invokeLinux.cpp: In function `int main()':
invokeLinux.cpp:24: error: `JNI_VERSION_1_4_2_05' undeclared (first use
this
function)
invokeLinux.cpp:24: error: (Each undeclared identifier is reported only
once
for each function it appears in.)



 
Reply With Quote
 
tony_lincoln@yahoo.com
Guest
Posts: n/a
 
      09-30-2005
Yes. I changed the path into:

rakta:~/GAQ$ export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jvm/java-1.4.2-sun-1.4.2_05/jre/lib/i386/server:/usr/lib/jvm/java-1.4.2-sun-1.4.2_05/jre/lib/i386

Then compile it, and the error kept the same:

invokeLinux.cpp: In function `int main()':
invokeLinux.cpp:24: error: `JNI_VERSION_1_4_2_05' undeclared (first use
this
function)
invokeLinux.cpp:24: error: (Each undeclared identifier is reported only
once
for each function it appears in.)

If I remove the line "vm_args.version = JNI_VERSION_1_4_2_05",
I can compile it, but the final result kept the same:
"Can't create Java VM"

Sorry for my questions.

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-30-2005
On 30 Sep 2005 08:59:19 -0700, (E-Mail Removed) wrote:
> You are right. My java version is 1.4.2_05.
> So I changed the codes into
> vm_args.version = JNI_VERSION_1_4_2_05;
>
> But the error kept the same:
>
> rakta:~/GAQ$ gcc -Wall -D_REENTRANT -I
> /home/gao/java/j2sdk1.4.2_08/include -I
> /home/gao/java/j2sdk1.4.2_08/include/linux-c invokeLinux.cpp
> invokeLinux.cpp: In function `int main()':
> invokeLinux.cpp:24: error: `JNI_VERSION_1_4_2_05' undeclared (first use
> this
> function)
> invokeLinux.cpp:24: error: (Each undeclared identifier is reported only
> once
> for each function it appears in.)


The only valid values are (AFAIK) JNI_VERSION_1_4, JNI_VERSION_1_2 and
JNI_VERSION_1_1, they are listed in jni.h.

The paths you mention in the example above don't agree with what
you've posted elsewhere, where you mentioned
/usr/lib/jvm/java-1.4.2-sun-1.4.2_05.

It seems you have several java versions installed. You need to make
sure you compile and link against the correct (and same) one.

/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
 
Gordon Beaton
Guest
Posts: n/a
 
      09-30-2005
On 30 Sep 2005 09:03:57 -0700, (E-Mail Removed) wrote:
> Yes. I changed the path into:
>
> rakta:~/GAQ$ export
> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jvm/java-1.4.2-sun-1.4.2_05/jre/lib/i386/server:/usr/lib/jvm/java-1.4.2-sun-1.4.2_05/jre/lib/i386
>
> Then compile it, and the error kept the same:


LD_LIBRARY_PATH has nothing to do with compiling the code. It's only
there to help find the libraries that are needed when you *run* the
program.

> invokeLinux.cpp: In function `int main()':
> invokeLinux.cpp:24: error: `JNI_VERSION_1_4_2_05' undeclared (first use
> this
> function)
> invokeLinux.cpp:24: error: (Each undeclared identifier is reported only
> once
> for each function it appears in.)
>
> If I remove the line "vm_args.version = JNI_VERSION_1_4_2_05",
> I can compile it, but the final result kept the same:
> "Can't create Java VM"


I've responded to this in another post. This JNI_VERSION isn't valid.

/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
 
tony_lincoln@yahoo.com
Guest
Posts: n/a
 
      09-30-2005
Thanks. I think that you are correct. I will try to compile and link
against the correct (and same) version tomorrow.
Thanks a lot and Have a nice weekend.
tony

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-30-2005
On 30 Sep 2005 07:06:42 -0700, (E-Mail Removed) wrote or quoted
:

>What do you mean "updatedb and locate"?


Are those not standard Linux commands? I has been a while. Look in a
bash manual.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-30-2005
On 30 Sep 2005 08:53:55 -0700, (E-Mail Removed) wrote or quoted
:

>I know that they are different. But what is the difference?


there are two versions of java.exe and its attendant dlls. You
control which one you get with the -server command line option.

The -server version is slower to start, but presumes it will keep
running the same code for a long time, so spends more time optimising
it.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
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
Tomcat 5.5+ On a Mac, Under Eclipse, Under OS X Edward V. Berard Java 4 04-04-2006 05:14 AM
Why does Rpy/R-plot work under PythonWin, but not under commandline/IDLE? Bo Peng Python 1 01-09-2006 07:05 AM
help : my jar file is not running under linux terminal , but it runs under JbuilderX ide bronby Java 1 07-15-2005 07:23 AM
[newbie]How to install python under DOS and is there any Wxpython can be installed under dos? john san Python 19 02-18-2005 12:05 PM
Java application developped under Linux running ridiculously slow under Windows hshdude Java 12 11-04-2004 05:49 PM



Advertisments