eclipse - DLL Call From Java Returns an UnsatisfiedLinkError -
edit: problem solved
i created new project , imported source files. (after trying many options project configuration wrong.) seems had confused load , loadlibrary functions. load requires absolute path including file postfix, e.g.:
static { system.load("c:/windows/system32/jnpout32.dll");}
when trying call jnpout32.dll (http://www.hytherion.com/beattidp/comput/pport.htm) java in eclipse (windows 7, java se1.7) receive error:
exception in thread "main" java.lang.unsatisfiedlinkerror: eegtrigger.ioport.out32(ss)v @ eegtrigger.ioport.out32(native method) @ eegtrigger.pport.setalldatabits(pport.java:53) @ eegtrigger.pport.<init>(pport.java:19) @ eegtrigger.eegtrigger.main(eegtrigger.java:11)
the dll file located in system32, in src folder, , in c:\users[user]\appdata\local (as indicated system.getenv())
in classpath under user entries, file loaded
jnpout32.dll - \[project]\src\[project]\
and visible under referenced libraries in package explorer
both these lines not work:
static { system.loadlibrary("jnpout32"); } static { system.load("c:/windows/system32/jnpout32"); }
(.load suggested in java.lang.unsatisfiedlinkerror - jni)
i have confirmed (based on java.lang.unsatisfiedlinkerror)
system.getproperty("java.library.path")
returns system32 path.
the complete code of java project (i have authored eegtrigger class. rest comes dll.):
package eegtrigger; public class eegtrigger { public static void main(string[] args) { // todo auto-generated method stub system.out.println("starting trigger..."); pport lpt1 = new pport(); testprotocol(lpt1); } private static void testprotocol(pport lpt1) { // todo auto-generated method stub short selecttrigger = 0; sendpulse(lpt1, selecttrigger); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } selecttrigger = 1; sendpulse(lpt1, selecttrigger); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } selecttrigger = 2; sendpulse(lpt1, selecttrigger); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } selecttrigger = 3; sendpulse(lpt1, selecttrigger); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } selecttrigger = 4; sendpulse(lpt1, selecttrigger); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } selecttrigger = 0; sendpulse(lpt1, selecttrigger); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } } /** * @param lpt1 */ public static void sendpulse(pport lpt1, short selecttrigger) { short trigger = 0; short targettrigger = 255; short stimulusonsetasynchrony = 64; short trialonsettrigger = 32; short triggeroff = 0; switch (selecttrigger) { case 1 : trigger = targettrigger; break; case 2 : trigger = stimulusonsetasynchrony; break; case 3 : trigger = trialonsettrigger; break; case 4 : trigger = triggeroff; break; default : trigger = triggeroff; break; } lpt1.output(trigger); try { thread.sleep(50); // 50 milliseconds } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } lpt1.output(triggeroff); } } package eegtrigger; /* definitions in build of jnpout32.dll are: */ /* short _stdcall inp32(short portaddress); */ /* void _stdcall out32(short portaddress, short data); */ public class ioport { // declare native methods of 'jnpout32.dll' // output value specified port address public native void out32(short portaddress, short data); // input value specified port address public native short inp32(short portaddress); // load 'jnpout32.dll' static { system.loadlibrary("jnpout32");} //static { system.load("c:/windows/system32/jnpout32"); } } package eegtrigger; // ** derived information provided on web dr. kenneth g. schweller, // ** ( http://web.bvu.edu/faculty/schweller/ ) , mars rover project page. public class pport { ioport pp; // wrapper class 'jnpout32.dll' // methods: // int out32(int port, int value); // int inp32(int port); short portaddress; // address of data port short currentval; // current value of port bits public pport() { pp = new ioport(); portaddress = (short)0x378; // hex address of data byte of pc parallel port setalldatabits((short)0); // initialize port bits 0 currentval = 0x00; } // wrap parallelport output method public void output(short port, short value) { pp.out32(port, value); } // wrap parallelport input method public short input(short port) { return pp.inp32(port); } // output default data port public void output(short value) { pp.out32(portaddress, value); } // input default data port public short input() { return pp.inp32(portaddress); } /** * set bits on data port 0 **/ public void setalldatabits(short value) { pp.out32(portaddress, value); currentval = value; } // users prefer dealing pin numbers // set pin <pin> <value> public void setpin(short pin, short value) { if (pin >= 2 && pin <= 9) // set corresponding data bit indicted value setdatabit((short)(pin-2), value); } /** * set data bit @ selected index value of 1 or 0 * while preserving current values of other data bits **/ void setdatabit(short index, short value) { switch(index) { case 0: if (value==0) // set data[0] 0 currentval = (short) (currentval & 0xfe); // aaaa aaaa currentval // , 1111 1110 mask // ========= // aaaa aaa0 new currentval else // set data[0] 1 currentval = (short) (currentval | 0x01); // aaaa aaaa currentval // or 0000 0001 mask // ========= // aaaa aaa1 new currentval break; case 1: if (value==0) currentval = (short) (currentval & 0xfd); // currentval = aaaa aa0a else currentval = (short) (currentval | 0x02); // currentval = aaaa aa1a break; case 2: if (value==0) currentval = (short) (currentval & 0xfb); // currentval = aaaa a0aa else currentval = (short) (currentval | 0x04); // currentval = aaaa a1aa break; case 3: if (value==1) currentval = (short) (currentval & 0xf7); // currentval = aaaa 0aaa else currentval = (short) (currentval | 0x08); // currentval = aaaa 1aaa break; case 4: if (value==0) currentval = (short) (currentval & 0xef); // currentval = aaa0 aaaa else currentval = (short) (currentval | 0x10); // currentval = aaa1 aaaa break; case 5: if (value==0) currentval = (short) (currentval & 0xdf); // currentval = aa0a aaaa else currentval = (short) (currentval | 0x20); // currentval = aa1a aaaa break; case 6: if (value==0) currentval = (short) (currentval & 0xbf); // currentval = a0aa aaaa else currentval = (short) (currentval | 0x40); // currentval = a1aa aaaa break; case 7: if (value==0) currentval = (short) (currentval & 0x7f); // currentval = 0aaa aaaa else currentval = (short) (currentval | 0x80); // currentval = 1aaa aaaa break; default: system.out.println("index must 0 - 7"); } pp.out32(portaddress, currentval); } }
the following questions either not helpful or not applicable in regard:
java.lang.unsatisfiedlinkerror
java.lang.unsatisfiedlinkerror
java.lang.unsatisfiedlinkerror
java.lang.unsatisfiedlinkerror
java.lang.unsatisfiedlinkerror in linux
java.lang.unsatisfiedlinkerror in eclipse
you haven't provided information why might getting unsatisfiedlinkerror. try attaching full stack trace.
system.loadlibrary("jnpout32") correct long java.library.path set when jvm starts via java -djava.library.path="%windir%/system32/"
if want use system.load, should system.load("c:/windows/system32/" + system.maplibraryname("jnpout32")) produce native library name , extension.
if using them , both continue fail, error somewhere else dependent library missing.
Comments
Post a Comment