• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JNI on UNIX help

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying to use JNI calls to C library in UNIX environment. I tried to run a simple hello world application using

java -Djava.library.path=. com.code.jni.Hello

I have the "libHello_JNI.so" library in the current directory. But why is it still complaining

Exception in thread "Main Thread" java.lang.UnsatisfiedLinkError: no Hello_JNI in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at com.fedex.jni.Hello.<clinit>(Hello.java:6)

I have tried setting the LD_LIBRARY_PATH to the directory containing "libHello_JNI.so". Even that did not work !!
Can anyone help me ?
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like library name passed to System.load() is wrong, doesn't it? Filename is "libHello_JNI" but exception says "Hello_JNI"...
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:Looks like library name passed to System.load() is wrong, doesn't it? Filename is "libHello_JNI" but exception says "Hello_JNI"...


With loadLibrary, you don't add the ".dll" in Windows or the starting "lib" and ending ".so" in Linux.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe libHello_JNI.so is not a valid shared library file. Maybe it's 64bit, and the JVM is 32-bit, or vice-versa? Maybe it's a "*.a" library, but you've named it as *.so?
 
Sri Harsha Yenuganti
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a source file Hello.cpp. The processor architecture is x86-64. I am generating the shared library using the following command :

gcc -shared -m64 -I/path/to/include/files -fPIC Hello.cpp -o libHello_JNI.so

This library is in the folder specified on the path. Even then I am getting the error !

Can you tell me where I am going wrong ?

Thank You.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic