zeromq / jzmq

Java binding for ZeroMQ
http://www.zeromq.org
GNU General Public License v3.0
590 stars 364 forks source link

UnsatisfiedLinkError: org.zeromq.ZMQ$Curve.generateKeyPair #403

Open molipet opened 8 years ago

molipet commented 8 years ago

ZMQ.Curve.generateKeyPair() does not work on a "standalone way". The below code-snippet throws UnsatisfiedLinkError:

import org.zeromq.ZMQ;
public class GenerateKeys {
    public static void main (String[] args) {
        ZMQ.Curve.KeyPair curve = ZMQ.Curve.generateKeyPair();
    }
}

The reason is that the native library is not loaded: only the ZMQ class has the library-loading static initializer block but the ZMQ.Curve class does not have it. Note: In the above snippet ZMQ class does not get initialized so static initializer is not called.

Possible workaround is to force the ZMQ class to be initialized so that the static initializer block is called and native library is loaded:

import org.zeromq.ZMQ;
public class GenerateKeys {
    public static void main (String[] args) {
        ZMQ.getMajorVersion();  // dummy call in order to load the native library
        ZMQ.Curve.KeyPair curve = ZMQ.Curve.generateKeyPair();
    }
}
msteinhoff commented 8 years ago

Would you add library loading to the ZMQ.Curve class and send a PR?