Java runtime error with JNI -


i trying build , run example jni program. program sample helloworld program. did not write assume works. running on linux. there 4 files.

hellonative.c   hellonative.h   hellonative.java   hellonativetest.java   

to build files, did

gcc -i/mydir/jdk/include -i/mydir/jdk/include/linux -fpic -c hellonative.c   gcc -shared -o hellonative.so hellonative.o   java *java 

here result of build

hellonative.c   hellonative.h        hellonative.o      hellonativetest.class   hellonative.class   hellonative.java   hellonative.so   hellonativetest.java 

then did

setenv ld_library_path /mydir/myexample:${ld_library_path}   java hellonativetest 

i got following error

exception in thread "main" java.lang.unsatisfiedlinkerror: no hellonative in java.library.path           @ java.lang.classloader.loadlibrary(classloader.java:1734)           @ java.lang.runtime.loadlibrary0(runtime.java:823)           @ java.lang.system.loadlibrary(system.java:1028)           @ hellonative.<clinit>(hellonative.java:9)           @ hellonativetest.main(hellonativetest.java:8)   

i checked ld_library_path , helloclasstest , hellonative.so, there. tried specify -classpath also, did not seem matter. have ideas ?

do following, x="hellonative".

  • give library filename following system-dependent standard. on linux, name library libx.so.
  • set java.library.path system property directory containing library.
  • call system.loadlibrary("x") "x" cross-platform part of library name above.

you named library hellonative.so; change libhellonative.so.

from http://download.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp679:

the argument system.loadlibrary library name chosen arbitrarily programmer. system follows standard, platform-specific, approach convert library name native library name. example, solaris system converts name pkg_cls libpkg_cls.so, while win32 system converts same pkg_cls name pkg_cls.dll.

if use osgi in future, there's alternative setting java.library.path.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -