Strange Loops

No Matter Where You Go, There You Are

Building ØMQ on My Mac

| Comments

In my plans for world domination, I need messaging software. I wanted to try out ZeroMQ (trying out RabbitMQ is for another weekend). I’m skipping ActiveMQ since we use it at work and I mostly understand what it provides.

Downloaded the tarball and it compiled right out of the box. However when I tried to get it to run with a simple java program I’ve written, I kept getting this error (this is on Leopard).

dc@feynman:dist$ java -Djava.library.path=/opt/personal/pkg/zmq/lib -classpath lib/Zmq.jar -jar ZmqTest.jar 
Creating ZMQ
Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/personal/pkg/zmq/lib/libjzmq.1.0.0.dylib: no suitable image found. Did find: /opt/personal/pkg/zmq/lib/libjzmq.1.0.0.dylib: mach-o, but wrong architecture /opt/personal/pkg/zmq/lib/libjzmq.1.0.0.dylib: mach-o, but wrong architecture
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1881)
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1805)
 at java.lang.Runtime.loadLibrary0(Runtime.java:823)
 at java.lang.System.loadLibrary(System.java:1045)
 at org.zmq.Zmq.(Zmq.java:25)
 at zmqtest.Main.main(Main.java:15)

As far as I can guess, the JVM I’m using is 64bit so the libraries it loads also need to be compiled as 64bits. To fix this, I had to set the CXXFLAGS environment variable to build 64 bits. This set of steps worked for me.

export CXXFLAGS="-arch x86_64" 
./configure --prefix=/opt/personal/pkg/zmq -with-java
make clean
make
make install

Here’s my small java program

package zmqtest;
import org.zmq.Zmq;

public class Main {
 public static void main(String[] args) {
  System.out.println("Creating ZMQ");
  Zmq zmq = new Zmq("localhost");
  System.out.println("Done creating ZMQ");
 }
}