JNI Phun.....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ian maclure

    JNI Phun.....


    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=HelloWorld Imp.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.Unsat isfiedLinkError : \
    <obfuscated>/JNI_d/libhello.so: \
    <obfuscated>/JNI_d/libhello.so: \
    ELF file's phentsize not the expected size
    at java.lang.Class Loader$NativeLi brary.load(Nati ve Method)
    at java.lang.Class Loader.loadLibr ary0(ClassLoade r.java:1560)
    at java.lang.Class Loader.loadLibr ary(ClassLoader .java:1485)
    at java.lang.Runti me.loadLibrary0 (Runtime.java:7 88)
    at java.lang.Syste m.loadLibrary(S ystem.java:834)
    at HelloWorld.<cli nit>(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 <><><><><><><>< >

  • ian maclure

    #2
    Re: JNI Phun.....

    On Fri, 26 Mar 2004 23:25:43 +0000, ian maclure wrote:
    [color=blue]
    >
    > 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.[/color]

    [snip]
    [color=blue]
    > ZZZZ=HelloWorld Imp.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[/color]

    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 <><><><><><><>< >

    Comment

    • Roman

      #3
      Re: JNI Phun.....

      You might want to include -fPic flag as well if you want position
      independent code.

      "ian maclure" <ibm@svpal.or g> wrote in message
      news:pan.2004.0 3.29.17.05.20.4 66711@svpal.org ...[color=blue]
      > On Fri, 26 Mar 2004 23:25:43 +0000, ian maclure wrote:
      >[color=green]
      > >
      > > 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.[/color]
      >
      > [snip]
      >[color=green]
      > > ZZZZ=HelloWorld Imp.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[/color][/color]
      libhello.so[color=blue]
      >
      > Problem was the "-c" in CPPOPT. Just run the preceding with
      > CPPOPT=shared and things work.
      >
      > IBM
      >
      >[/color]
      _______________ _______________ _______________ _______________ _______________ _
      ___[color=blue]
      > Posted Via Uncensored-News.Com - Accounts Starting At $6.95 -[/color]
      http://www.uncensored-news.com[color=blue]
      > <><><><><><>< > The Worlds Uncensored News Source[/color]
      <><><><><><><>< >[color=blue]
      >[/color]


      Comment

      Working...