I'm having problems running a JNI hello-world (native part in an linux shared object (.so) written in C).
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   p_feito
Posted On:   Wednesday, May 7, 2003 12:09 PM

I'm having problems running a JNI hello-world (native part in an .so (C)) example in Linux that i previously compiled and runned flawless on Windows with the native being written in C (DLL). The code is very simple: [JNIHelloWorld.java] public class JNIHelloWorld { public native void displayHelloWorld(); static { System.loadLibrary("hello"); } public static void main(String[] args) { new JNIHelloWorld().displayHelloWorld(); } public JNIHelloWorld() { System.out.println("JAVA - HelloWorld!"); } } [hello.c] #include #include "JNIHe   More>>
I'm having problems running a JNI hello-world (native part in an .so

(C)) example in Linux that i previously compiled and runned flawless on Windows with the native being written in C (DLL).


The code is very simple:



			
[JNIHelloWorld.java]
public class JNIHelloWorld {
public native void displayHelloWorld();

static {
System.loadLibrary("hello");
}

public static void main(String[] args) {
new JNIHelloWorld().displayHelloWorld();
}

public JNIHelloWorld() {
System.out.println("JAVA - HelloWorld!");
}
}


			
[hello.c]
#include
#include "JNIHelloWorld.h"
#include

JNIEXPORT void JNICALL
Java_JNIHelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("C (.so) - HelloWorld!
");
return;
}




Note: i compiled JNIHelloWorld.java and created the JNIHelloWorld.h with "javah -jni JNIHelloWorld". Then i created hello.so with "gcc -o hello.so -shared hello.c".


I have these files in /home/pfeito/java.
I created a /home/pfeito/java/lib to where i copied hello.so

I edited /etc/ld.so.conf and added /home/pfeito/java/lib and i edited ~/.bash_profile where i inserted these lines:

			
LD_LIBRARY_PATH=/home/pfeito/java/lib
export LD_LIBRARY_PATH

and then i executed "source ~/.bash_profile" so changes are made. When i execute "echo $LD_LIBRARY_PATH", i correctly get "/home/pfeito/java/lib" so im sure LD_LIBRARY_PATH is set. Then i even rebooted the machine because i wasn't sure if /etc/ld.so.conf changes are automatically in use after editing.



Finally i went to /home/pfeito/java and executed the application with "java JNIHelloWorld" but i got:



			
Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello.so in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at JNIHelloWorld. (JNIHelloWorld.java:16)



No matter what verifications and minor changes i made to this, i always got this error. What am i doing wrong ? I underline again that this same code runned flawless in windows environment.



Thanks in advance,



pfeito
   <<Less

Re: I'm having problems running a JNI hello-world (native part in an linux shared object (.so) written in C).

Posted By:   philomina_dorai  
Posted On:   Thursday, July 17, 2003 03:22 AM

try using System.load()method , include the complete library path and check if it works.
-philomina.

Re: I'm having problems running a JNI hello-world (native part in an linux shared object (.so) written in C).

Posted By:   Laukik_Chitnis  
Posted On:   Saturday, May 24, 2003 09:58 AM

Check this out...
this should help:

http://www.blackdown.org/java-linux/docs/support/faq-release/examples/

Regards,
Laukik Chitnis

Re: I'm having problems running a JNI hello-world (native part in an linux shared object (.so) written in C).

Posted By:   Dutour_Mathias  
Posted On:   Thursday, May 15, 2003 09:37 AM

Hello, I hope this can help...
On linux the naming convention for the library is :
lib.so
Then the Hello.dll on Windows becomes a libHello.so on Linux. Give it a try.
Good luck, Mathias.
About | Sitemap | Contact