Since everybody seemed to be stuck with using the library on windows and yet on linux it worked from the start I’ve decided to dive into the wonderful world of windoze.

The problem: while trying to use a java, jni-based library the error was unavoidable:

java.lang.UnsatisfiedLinkError: C:\sw_api\sw_api\windows\sw_api.dll: The operating system cannot run %1
                        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
                        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
                        at java.lang.ClassLoader.loadLibrary(Unknown Source)
                        at java.lang.Runtime.loadLibrary0(Unknown Source)
                        at java.lang.System.loadLibrary(Unknown Source)

As such I decided to wrote this simple program:

public class Test
{
    static
    {
            System.loadLibrary( "sw_api" );
            System.loadLibrary( "SWAPILink" );
        }
        catch( UnsatisfiedLinkError e ) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main(String argv[]){
        System.out.println("success");
    }
}

which of course gave the same problem. This was obviously not a PATH problem which would have caused a more general error such as:

java.lang.UnsatisfiedLinkError: no sw_api in java.library.path
                        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
                        at java.lang.Runtime.loadLibrary0(Runtime.java:823)
                        at java.lang.System.loadLibrary(System.java:1030)
                        at Test.<clinit>(Test.java:10)

As such the sw_api.dll was probably found but during load some error occured. And what happens during load? It loads some other dll’s. By taking a look in the path where the sw_api.dll was located I found a lot of sw_*.dll but also ssleay32.dll and libeay32.dll. The ssl versions are known to cause problems even on linux and by doing a search for the ssleay32.dll I found at least 5 instances of 3 different versions.

Multiple versions Multiple versions

So cause of the problem was that my sw_api.dll was trying to load the symbols for a function probably not present. In order to confirm this idea I modified my test code as such:

System.load( "C:\\sw_api\\sw_api\\windows\\libeay32.dll");
System.load( "C:\\sw_api\\sw_api\\windows\\ssleay32.dll");
System.loadLibrary( "sw_api" );

and yes, it worked. Sounds ok but this is no solution to hardcode some dll’s. Wondering who of is using this dll? Well even the intel driver for the wireless card is using it:

Who? Who?

First try: put the DLL path before %PATH%

set PATH=C:\sw_api\sw_api\windows;%PATH%

not working.

Second try: I found this link where the dynamic library search order is described. The solution was in fact to run the application from the DLL directory and as such impose these to be loaded first.

The elegant solution: would be to rename the problem dll’s as: sw-libeay32.dll and sw-ssleay32.dll and modify the sw-api.dll to use them. Of course this is not possible since it would require recompilation of this dll file.

Am I not entitled to miss the LD_PRELOAD ?