Search code examples
c++macoszeromq

How to get ZeroMQ as a 32bit library and merge it with the standard 64bit library?


Installing ZeroMQ (v4.2.2) is a breeze with either configure/make/install or with homebrew, but only the 64bit version is available. I tried brew's --universal option, but it says a universal option is not available and so the flag is ignored.

$ brew install zmq --universal
Warning: zeromq: this formula has no --universal option so it will be ignored!

My question is thus, how do I get a 32bit library version of ZeroMQ?

And, if I have other projects that still require the 64bit version, how do I create a universal binary so that those projects still work as well?


Solution

  • Library files for ZeroMQ are installed in the standard /usr/local/lib location, but if brew is used to install ZeroMQ, symlinks are created to the /usr/local/Cellar/zeromq/4.2.2/lib location. If you look at that directory, you will find libzmq.a and libzmq.5.dylib. Both of these files are 64bit and must be merged with a 32bit version.

    If you download ZeroMQ from their website, you can change the configure script as follows:

    ./configure CC="gcc -m32" CXX="g++ -m32" --prefix=`pwd`/i32
    

    The CC flag and CXX flag tells the script to configure for a 32bit version (see here). The prefix flag runs the pwd command to instruct the configure script to install files to the user i32 directory in the present working directory. make && make install ZeroMQ as usual and you should have 32bit libraries in the ./i32/lib directory. You can rename these files to reflect their 32bit nature:

    mv ./i32/lib/libzmq.a ./i32/lib/libzmq_i32.a
    mv ./i32/lib/libzmq.5.dylib ./i32/lib/libzmq_i32.5.dylib
    

    Both the .a and .dylib file must be merged to form a universal binaries, as you can see here and here. Start by changing directory to the location where the 64bit libraries are found, /usr/local/lib or /usr/local/Cellar/zeromq/4.2.2/lib. You can rename the library files to reflect their 64bit nature:

    mv libzmq.a libzmq_i64.a
    mv libzmq.5.dylib libzmq_i64.5.dylib 
    

    Merging the libraries is via the lipo command:

    lipo -create zeromq-4.2.2/i32/lib/libzmq_i32.a libzmq_i64.a -output libzmq.a
    lipo -create zeromq-4.2.2/i32/lib/libzmq_i32.5.dylib libzmq_i64.5.dylib -output libzmq.5.dylib
    

    Note that the symlink libzmq.dylib -> libzmq.5.dylib will still be valid.

    That's it!