Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: (JNA) java.lang.UnsatisfiedLinkError: Unable to load library

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default (JNA) java.lang.UnsatisfiedLinkError: Unable to load library

    Hi, I've been trying to use Bass Sound Engine in my projects as the audio library, so I've started coding the JNA wrapper for it. But after trying with only Init, Free and Play functions it just can't find the DLL.
    So, I've tried running my old JNA project using DLLs that actually worked before. No luck, same story - "java.lang.UnsatisfiedLinkError: Unable to load library".

    I've tried for about 4 hours today to get it working, but still, no luck.
    Here is my code:

    package pl.org.shocker.lib39dll;
     
    import com.sun.jna.Library;
    import com.sun.jna.Native;
     
    interface JNALib extends Library {
    	JNALib lib = (JNALib)Native.loadLibrary("39dll",JNALib.class);
     
    	double tcpconnect(String ip, double port, double mode);
    	double tcplisten(double port, double maxClients, double mode);
    	double tcpaccept(double sockID, double mode);
     
    	double udpconnect(double port, double mode);
    	double closesock(double sockID);
    	double sockstart();
    	double sockexit();
    	double socklasterror(double sockID);
    	double getsocketid(double sockID);
     
    	String tcpip(double sockID);
    	double setnagle(double sockID, double value);
    	double tcpconnected(double sockID);
    	double setformat(double sockID, double mode, String separator);
    	String lastinIP();
    	double lastinPort();
    	double setsync(double sockID, double mode);
    	String myhost();
    	String hostip(String host);
    	double compareip(String ip, String mask);
     
    	double sendmessage(double sockID, String ip, double port, double bufID);
    	double receivemessage(double sockID, double len, double bufID);
    	double peekmessage(double sockID, double len, double bufID);
     
    	double writebyte(double val, double bufID);
    	double writeshort(double val, double bufID);
    	double writeushort(double val, double bufID);
    	double writeint(double val, double bufID);
    	double writeuint(double val, double bufID);
    	double writefloat(double val, double bufID);
    	double writedouble(double val, double bufID);
    	double writechars(String string, double bufID);
    	double writestring(String string, double bufID);
     
    	double readbyte(double bufID);
    	double readshort(double bufID);
    	double readushort(double bufID);
    	double readint(double bufID);
    	double readuint(double bufID);
    	double readfloat(double bufID);
    	double readdouble(double bufID);
    	String readchars(double len, double bufID);
    	String readstring(double bufID);
    	String readsep(String separator, double bufID);
     
    	double getpos(double pos, double bufID);
    	double clearbuffer(double bufID);
    	double buffsize(double bufID);
    	double setpos(double pos, double bufID);
    	double bytesleft(double bufID);
     
    	double createbuffer();
    	double freebuffer(double bufID);
    	double copybuffer(double destID, double srcID);
    	double copybuffer2(double destID, double start, double len, double srcID);
     
    	String getmacaddress();
    	String md5string(String string);
    	String md5buffer(double bufID);
    	double bufferencrypt(String pass, double bufID);
    	double adler32(double bufID);
    	double bufferexists(double bufID);
    	double netconnected();
     
    	double fileopen(String name, double mode);
    	double fileclose(double fileID);
    	double filewrite(double fileID, double bufID);
    	double fileread(double fileID, double bytes, double bufID);
    	double filepos(double fileID);
    	double filesetpos(double fileID, double pos);
    	double filesize(double fileID);
     
    	double iptouint(String ip);
    	String uinttoip(double uint);
    }
    package pl.org.shocker.lib39dll;
     
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.BitSet;
     
    public class Lib39dll {
    	static boolean init = false;
    	static ArrayList<Buffer> buffers = new ArrayList<Buffer>();
    	static ArrayList<LibFile> files = new ArrayList<LibFile>();
    	private static final File pathTemp = new File(System.getProperty("java.io.tmpdir"));
     
    	static {
    		System.setProperty("jna.library.path",new File(System.getProperty("java.io.tmpdir")).getAbsolutePath());
    		File f = new File(pathTemp,"39dll.dll");
    		f.deleteOnExit();
    	}
     
    	public static void libInit() {
    		if (init) return;
    		copy("39dll.dll",new File(pathTemp,"39dll.dll"));
     
    		JNALib.lib.sockstart();
    		init = true;
    	}
    	public static void libDeinit() {
    		if (!init) return;
     
    		try {
    			for (int i = 0; i < buffers.size(); i++) buffers.get(i).free();
    			for (int i = 0; i < files.size(); i++) files.get(i).close();
    		} catch (Lib39dllException e) {}
     
    		JNALib.lib.sockexit();
    		init = false;
    	}
    	public static boolean libIsInit() throws Lib39dllException {
    		if (!init) throw new Lib39dllException("Not initialized");
    		return true;
    	}
     
    	public static boolean netConnected() throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.netconnected() == 1 ? true : false;
    	}
    	public static String myHost() throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.myhost();
    	}
    	public static String myMAC() throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.getmacaddress();
    	}
    	public static boolean matchesIP(String ip, String mask) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.compareip(ip,mask) == 1 ? true : false;
    	}
     
    	public static String hostIP(String host) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.hostip(host);
    	}
    	public static long ip2uint(String ip) throws Lib39dllException {
    		libIsInit();
    		return (long)JNALib.lib.iptouint(ip);
    	}
    	public static String uint2ip(long uint) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.uinttoip(uint);
    	}
     
    	public static boolean bufferExists(Buffer buffer) throws Lib39dllException {
    		return buffer.exists();
    	}
    	public static boolean bufferExists(int bufID) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.bufferexists(bufID) == 1 ? true : false;
    	}
    	public static String md5(String str) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.md5string(str);
    	}
    	public static String md5(Buffer buf) throws Lib39dllException {
    		return buf.md5();
    	}
     
    	public static BitSet getBitSet(int val) {
    		BitSet bs = new BitSet(8);
    		for (int i = 0; i < 8; i++) if ((val & (int)Math.pow(2,i)) > 0) bs.set(i);
    		return bs;
    	}
    	public static int getByte(BitSet bs) {
    		int value = 0;
    		for (int i = 0; i < 8; i++) if (bs.get(i)) value += Math.pow(2,i);
    		return value;
    	}
     
    	private static void copy(String fname, File path) {
    		try {
    			InputStream in = Lib39dll.class.getClassLoader().getResourceAsStream(fname);
    			FileOutputStream out = new FileOutputStream(path);
    			byte[] buf = new byte[1024]; int len;
    			while ((len = in.read(buf)) > 0) out.write(buf,0,len);
    			in.close(); out.close();
    		} catch (Exception e) {e.printStackTrace();}
    	}
    }
    import pl.org.shocker.lib39dll.Lib39dll;
     
    public class App {
    	public static void main(String[] args) {
    		Lib39dll.libInit();
    		Lib39dll.libDeinit();
    	}
    }

    And the error I get:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library '39dll': Nie mo?na odnale?? okre?lonego modu?
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrar y.java:166)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrar y.java:239)
    at com.sun.jna.Library$Handler.<init>(Library.java:14 0)
    at com.sun.jna.Native.loadLibrary(Native.java:393)
    at com.sun.jna.Native.loadLibrary(Native.java:378)
    at pl.org.shocker.lib39dll.JNALib.<clinit>(JNALib.jav a:7)
    at pl.org.shocker.lib39dll.Lib39dll.libInit(Lib39dll. java:25)
    at App.main(App.java:5)
    And the old code that worked before (but now isn't working):
    package pl.org.shocker.lib39dll;
     
    import com.sun.jna.Library;
    import com.sun.jna.Native;
     
    interface JNALib extends Library {
    	JNALib lib = (JNALib)Native.loadLibrary("39dll",JNALib.class);
     
    	double tcpconnect(String ip, double port, double mode);
    	double tcplisten(double port, double maxClients, double mode);
    	double tcpaccept(double sockID, double mode);
     
    	double udpconnect(double port, double mode);
    	double closesock(double sockID);
    	double sockstart();
    	double sockexit();
    	double socklasterror(double sockID);
    	double getsocketid(double sockID);
     
    	String tcpip(double sockID);
    	double setnagle(double sockID, double value);
    	double tcpconnected(double sockID);
    	double setformat(double sockID, double mode, String separator);
    	String lastinIP();
    	double lastinPort();
    	double setsync(double sockID, double mode);
    	String myhost();
    	String hostip(String host);
    	double compareip(String ip, String mask);
     
    	double sendmessage(double sockID, String ip, double port, double bufID);
    	double receivemessage(double sockID, double len, double bufID);
    	double peekmessage(double sockID, double len, double bufID);
     
    	double writebyte(double val, double bufID);
    	double writeshort(double val, double bufID);
    	double writeushort(double val, double bufID);
    	double writeint(double val, double bufID);
    	double writeuint(double val, double bufID);
    	double writefloat(double val, double bufID);
    	double writedouble(double val, double bufID);
    	double writechars(String string, double bufID);
    	double writestring(String string, double bufID);
     
    	double readbyte(double bufID);
    	double readshort(double bufID);
    	double readushort(double bufID);
    	double readint(double bufID);
    	double readuint(double bufID);
    	double readfloat(double bufID);
    	double readdouble(double bufID);
    	String readchars(double len, double bufID);
    	String readstring(double bufID);
    	String readsep(String separator, double bufID);
     
    	double getpos(double pos, double bufID);
    	double clearbuffer(double bufID);
    	double buffsize(double bufID);
    	double setpos(double pos, double bufID);
    	double bytesleft(double bufID);
     
    	double createbuffer();
    	double freebuffer(double bufID);
    	double copybuffer(double destID, double srcID);
    	double copybuffer2(double destID, double start, double len, double srcID);
     
    	String getmacaddress();
    	String md5string(String string);
    	String md5buffer(double bufID);
    	double bufferencrypt(String pass, double bufID);
    	double adler32(double bufID);
    	double bufferexists(double bufID);
    	double netconnected();
     
    	double fileopen(String name, double mode);
    	double fileclose(double fileID);
    	double filewrite(double fileID, double bufID);
    	double fileread(double fileID, double bytes, double bufID);
    	double filepos(double fileID);
    	double filesetpos(double fileID, double pos);
    	double filesize(double fileID);
     
    	double iptouint(String ip);
    	String uinttoip(double uint);
    }
     
     
     
    package pl.org.shocker.lib39dll;
     
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.BitSet;
     
    import com.sun.jna.NativeLibrary;
     
    public class Lib39dll {
    	static boolean init = false;
    	static ArrayList<Buffer> buffers = new ArrayList<Buffer>();
    	static ArrayList<LibFile> files = new ArrayList<LibFile>();
    	private static File pathTemp;
     
    	static {
    		File f = new File(pathTemp,"39dll.dll");
    		f.deleteOnExit();
    	}
     
    	public static void libInit() {
    		if (init) return;
     
    		pathTemp = new File(System.getProperty("java.io.tmpdir"));
    		NativeLibrary.addSearchPath("39dll",pathTemp.getParentFile().getAbsolutePath());
    		try {
    			InputStream in = Lib39dll.class.getClassLoader().getResourceAsStream("39dll.dll");
    			FileOutputStream out = new FileOutputStream(new File(pathTemp,"39dll.dll"));
    			byte[] buf = new byte[1024]; int len;
    			while ((len = in.read(buf)) > 0) out.write(buf,0,len);
    			in.close(); out.close();
    		} catch (FileNotFoundException e) {e.printStackTrace();
    		} catch (IOException e) {e.printStackTrace();}
     
    		JNALib.lib.sockstart();
    		init = true;
    	}
    	public static void libDeinit() {
    		if (!init) return;
     
    		try {
    			for (int i = 0; i < buffers.size(); i++) buffers.get(i).free();
    			for (int i = 0; i < files.size(); i++) files.get(i).close();
    		} catch (Lib39dllException e) {}
     
    		JNALib.lib.sockexit();
    		init = false;
    	}
    	public static boolean libIsInit() throws Lib39dllException {
    		if (!init) throw new Lib39dllException("Not initialized");
    		return true;
    	}
     
    	public static boolean netConnected() throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.netconnected() == 1 ? true : false;
    	}
    	public static String myHost() throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.myhost();
    	}
    	public static String myMAC() throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.getmacaddress();
    	}
    	public static boolean matchesIP(String ip, String mask) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.compareip(ip,mask) == 1 ? true : false;
    	}
     
    	public static String hostIP(String host) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.hostip(host);
    	}
    	public static long ip2uint(String ip) throws Lib39dllException {
    		libIsInit();
    		return (long)JNALib.lib.iptouint(ip);
    	}
    	public static String uint2ip(long uint) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.uinttoip(uint);
    	}
     
    	public static boolean bufferExists(Buffer buffer) throws Lib39dllException {
    		return buffer.exists();
    	}
    	public static boolean bufferExists(int bufID) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.bufferexists(bufID) == 1 ? true : false;
    	}
    	public static String md5(String str) throws Lib39dllException {
    		libIsInit();
    		return JNALib.lib.md5string(str);
    	}
    	public static String md5(Buffer buf) throws Lib39dllException {
    		return buf.md5();
    	}
     
    	public static BitSet getBitSet(int val) {
    		BitSet bs = new BitSet(8);
    		for (int i = 0; i < 8; i++) if ((val & (int)Math.pow(2,i)) > 0) bs.set(i);
    		return bs;
    	}
    	public static int getByte(BitSet bs) {
    		int value = 0;
    		for (int i = 0; i < 8; i++) if (bs.get(i)) value += Math.pow(2,i);
    		return value;
    	}
    }

    What's wrong?
    Last edited by Shockah; September 24th, 2011 at 12:13 PM.


  2. #2
    Member
    Join Date
    Sep 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: (JNA) java.lang.UnsatisfiedLinkError: Unable to load library

    Where do you put the DLL file? It should be under windows or system folder.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: (JNA) java.lang.UnsatisfiedLinkError: Unable to load library

    As you can see, my DLL file is in the JAR, and I'm copying it to temp folder where it was loading it just fine. Now, even when I set jna.library.path to the temp folder path, it won't load it.

  4. #4
    Member
    Join Date
    Sep 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: (JNA) java.lang.UnsatisfiedLinkError: Unable to load library

    Quote Originally Posted by Shockah View Post
    As you can see, my DLL file is in the JAR, and I'm copying it to temp folder where it was loading it just fine. Now, even when I set jna.library.path to the temp folder path, it won't load it.
    Have you tried to put the DLL under System folder? Normally DLLs should be put under System folder or at the same level as the executable jar file.

    java memory
    Last edited by namhm; December 4th, 2011 at 06:53 PM.

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: (JNA) java.lang.UnsatisfiedLinkError: Unable to load library

    Tried with C:\Windows and C:\Windows\system32. Anyway, as I said, it shouldn't matter.

Similar Threads

  1. Java Applet Will Not Load.
    By PaulMoretti in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 17th, 2011, 05:42 AM
  2. Help ! java.lang.UnsatisfiedLinkError
    By CTheSky in forum Java Theory & Questions
    Replies: 1
    Last Post: July 7th, 2011, 12:50 PM
  3. Replies: 1
    Last Post: March 21st, 2011, 09:01 AM
  4. java.lang.UnsatisfiedLinkError
    By H P in forum Java Native Interface
    Replies: 3
    Last Post: January 28th, 2010, 05:04 AM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM

Tags for this Thread