• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI on UNIX help  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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 C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • 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: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.


 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!