By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,041 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,041 IT Pros & Developers. It's quick & easy.

JNI Phun.....

P: n/a

I'm trying to understand JNI well enough to be be able to supply
a state model class in C++ to some client applications and use the
same model in the JAVA app that controls the clients.
The state model class is written.
I thought a good place to start might be with the JAVA JNI Tutorial
HelloWorld instance, so I set up HelloWorld.java, compiled it, ran it
through javah, setup the HelloWorldImp.c ( native C language method )
and compiled it per the instructions ( or what the instructions implied ):

got HelloWorld.java
java HelloWorld.java
javah -jni HelloWorld
checked HelloWorld.h
got HelloWorldImp.c

Set LD_LIBRARY_PATH to the PWD since thats where everything resides

compiled HelloWorldImp.c as follow:

ZZZZ=HelloWorldImp.c
JJJJ=/usr/java/sdk ( 1.4.2_01 as it happens )
CPPOPT="-c -g -shared"
gcc $CPPOPT -I$JJJJ/include -I$JJJJ/include/linux $ZZZZ -o libhello.so
I am running on a RedHat 9 Linux box by the way.

Got the resulting libhello.so and then tried to run the app

java HelloWorld

What I got was:

Exception in thread "main" java.lang.UnsatisfiedLinkError: \
<obfuscated>/JNI_d/libhello.so: \
<obfuscated>/JNI_d/libhello.so: \
ELF file's phentsize not the expected size
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.jav a:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1485)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at HelloWorld.<clinit>(HelloWorld.java:15)

No idea what this means although I suspect it has something to do with the
compilation of HelloWorldImp.c.
What have I done ( or not ) as the case may be.

Thanx.....

IBM

__________________________________________________ _____________________________
Posted Via Uncensored-News.Com - Accounts Starting At $6.95 - http://www.uncensored-news.com
<><><><><><><> The Worlds Uncensored News Source <><><><><><><><>

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 26 Mar 2004 23:25:43 +0000, ian maclure wrote:

I'm trying to understand JNI well enough to be be able to supply
a state model class in C++ to some client applications and use the
same model in the JAVA app that controls the clients.
[snip]
ZZZZ=HelloWorldImp.c
JJJJ=/usr/java/sdk ( 1.4.2_01 as it happens )
CPPOPT="-c -g -shared"
gcc $CPPOPT -I$JJJJ/include -I$JJJJ/include/linux $ZZZZ -o libhello.so


Problem was the "-c" in CPPOPT. Just run the preceding with
CPPOPT=shared and things work.

IBM

__________________________________________________ _____________________________
Posted Via Uncensored-News.Com - Accounts Starting At $6.95 - http://www.uncensored-news.com
<><><><><><><> The Worlds Uncensored News Source <><><><><><><><>

Jul 17 '05 #2

P: n/a
You might want to include -fPic flag as well if you want position
independent code.

"ian maclure" <ib*@svpal.org> wrote in message
news:pa****************************@svpal.org...
On Fri, 26 Mar 2004 23:25:43 +0000, ian maclure wrote:

I'm trying to understand JNI well enough to be be able to supply
a state model class in C++ to some client applications and use the
same model in the JAVA app that controls the clients.
[snip]
ZZZZ=HelloWorldImp.c
JJJJ=/usr/java/sdk ( 1.4.2_01 as it happens )
CPPOPT="-c -g -shared"
gcc $CPPOPT -I$JJJJ/include -I$JJJJ/include/linux $ZZZZ -o

libhello.so
Problem was the "-c" in CPPOPT. Just run the preceding with
CPPOPT=shared and things work.

IBM

__________________________________________________ __________________________
___ Posted Via Uncensored-News.Com - Accounts Starting At $6.95 - http://www.uncensored-news.com <><><><><><><> The Worlds Uncensored News Source <><><><><><><><>

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.