eclipse - Loading native libraries in java -


i have eclipse project 2 classes. class "someclass1" has native method:

someclass1

public class someclass1 {     static {         system.loadlibrary("libname"); // load native library.     }     public native void some_method(); // implemented in library     // .... other non methods .... } 

the other class "someclass2" uses native method of "someclass1". like:

someclass2

public class someclass2{     public static void main(string[] args) {         someclass1 s = new someclass1();         s.some_method();     }     // ....other methods.... } 

however when calls method throws error this:

exception in thread "main" java.lang.unsatisfiedlinkerror: no libname in java.library.path .... @ java.lang.system.loadlibrary(unknown source) @ x.x.x.someclass1.<clinit>(someclass1.java:128) @ someclass2.main(someclass2.java:10) 

i think error has java not knowing native library.

question1 when use: -djava.library.path="c:\users.....\libfolder\" run argument in eclipse , print value of: system.getproperty("java.library.path"); see alot of directories printed not directory specified in argument. doing wrong?

question2 when do: system.loadlibrary("name"); need call library "name.so" or "libname.so"?

question3 if library found 64 bit library while platform loaded on 32 bit, give unsatisfiedlinkerror or different error given?

question4 can specify path library relative projects folder or relative file in library loaded?

hope able answer (some of) questions.

grtz stefan

question 1:

you should not add run argument, vm argument. it's not argument program, jvm.

question 2:

(also @ianroberts ) : system.loadlibrary(name) call automatically derive name of actual library given name. means append ".dll" on windows, , use "lib" + name + ".so" on linux. otherwise, loading native lib not possible in platform-independent way!

question 3:

in general, unsatsfiedlinkerror distressingly common. it's in fact true say: unsatisfiedlinkerror not tell more "something wrong". can hope actual error message more descriptive, , (fortunately) case if had 32/64bit mismatch - @ least on windows:

  • trying load 32bit lib on 64bit system cause message: "can't load ia 32-bit .dll on amd 64-bit platform"
  • trying load 64bit lib on 32bit system cause message: "... not valid win32 application"

(i'm not sure message other operating systems, though, your message indicates library not found, , not there's problem library itself)

(question 4: i'm rather sure possible, not absolutely sure (and can't try out) @ moment. in general, library must in path visible via path environment variable, or via java.library.path. in doubt, should work native libs in same directory starting program from)


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -