Hot questions for Using ZeroMQ in macos

Question:

I'm trying to receive information from an 0MQ Socket in C or C++, but therefore I have to include zmq.h. By downloading the 0MQ software from their website and including this file. Xcode gives the following error:

Undefined symbols for architecture x86_64: "_zmq_init", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

When installing ZeroMQ using brew I get the same error. Is there anyone who know a workaround?


Answer:

The problem here is that you aren't linking the ZMQ library correctly.

You need to build the library once you've downloaded it (they include all the make scripts you need). Once you have that, you will need to link them to the compiler. I'm not too familiar with XCode, but using gcc it would look something like this:

-L/path/to/zmq/library -lzmq

ZeroMQ is really beautiful though. I've used it on Linux/Windows. Hope you get it working!

Question:

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?


Answer:

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!

Question:

I wanted to implement ICP on Mac OSX, so I learned about ZeroMQ through googling. I installed ZeroMQ using the brew install zmq command However, there is very little information about ZeroMq on Mac OSX, so I am having difficulty with some problems.

This is an example uploaded on the ZeroMQ homepage.

public static void HWClient(string[] args)
{

using (var context = new ZContext())
using (var requester = new ZSocket(context, ZSocketType.REQ))
{
    // Connect
    requester.Connect("tcp://127.0.0.1:5555");

    for (int n = 0; n < 10; ++n)
    {
        string requestText = "Hello";
        Console.Write("Sending {0}...", requestText);

        // Send
        requester.Send(new ZFrame(requestText));

        // Receive
        using (ZFrame reply = requester.ReceiveFrame()) 
        {
            Console.WriteLine(" Received: {0} {1}!", requestText, reply.ReadString());
        }
    }
}
}

When I run these code, I'll get an exception The type initializer for 'ZeroMQ.lib.zmq' threw an exception. There are many ways to fix the exception, but there is no solution in Mac OSX.

Please help me...


Answer:

I found that the released version of https://github.com/zeromq/clrzmq4 works under MacOS X only under very special circumstances, due to several issues related to loading the native libzmq library. This is fixed to some degree in the master. There is now CI under MacOS X, so you can have a look at the CI script under https://github.com/zeromq/clrzmq4/blob/master/build.sh for one way of installing and building that works.

Question:

I installed boot2docker as explained on the docker website. Here are some command runs to show that I have things installed correctly:

$$:~ kv$ boot2docker start
Waiting for VM and Docker daemon to start...
...................ooo
Started.
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/key.pem
Your environment variables are already set correctly.

$$:~ kv$ docker images
REPOSITORY  TAG     IMAGE ID        CREATED             VIRTUAL SIZE
ubuntu     14.04   b39b81afc8ca        11 days ago         188.3 MB
hello-world  latest e45a5af57b00        3 weeks ago         910 B

After this, I ran the following command:

docker run -t -i ubuntu:14.04 /bin/bash

Inside the container, I installed zeromq, and started a zeromq server on port 5555 using tcp.

My questions are following:

  1. If I exit out of the container, will it save all the work I do inside it?

  2. I have no idea how to connect to the server running on port 5555. I read something about exposing a port, but I am not sure how to go about doing that. I did an ifconfig inside the container, and tried to connect to the server from the host like this:

    $$:~ kv$ ./zmq_client tcp://container_ip:5555
    

    This did not work. Can someone please lists the steps I need to take in order to connect to the server running within the container.

For completion sake, I am providing the list of my environment variables:

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/km/5kbpdx4s7cg4rmyc6d5q9l9r0000gq/T/
DOCKER_HOST=tcp://192.168.109.103:2376
Apple_PubSub_Socket_Render=/tmp/launch-1tWMHJ/Render
TERM_PROGRAM_VERSION=326
OLDPWD=/Users
TERM_SESSION_ID=262CBC8B-0A74-4B70-9F28-D9FA51FF713C
USER=kv
SSH_AUTH_SOCK=/tmp/launch-ZTWNGL/Listeners
__CF_USER_TEXT_ENCODING=0x1F7:0:0
DOCKER_TLS_VERIFY=1
__CHECKFIX1436934=1
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
PWD=/Users/kv
DOCKER_CERT_PATH=/Users/kv/.boot2docker/certs/boot2docker-vm
HOME=/Users/kv
SHLVL=1
LOGNAME=kv
LC_CTYPE=UTF-8
DISPLAY=/tmp/launch-rco9zt/org.macosforge.xquartz:0
_=/usr/bin/env

One last question I have is about code performance. So within my Mac OS X, I have a docker container running (which runs Ubuntu). If I run the application, like a zeromq based server inside the container, will it not be slower as compared to running it on Mac OS X directly. Please explain the benefits of using docker in such a scenario..


Answer:

You should really do some more reading and research before turning to SO, then ask about anything you can't figure out. But:

  1. No. If the container is "exited" you can restart it and your files will still be there, but once it is removed your files are gone. You can use docker commit to save them to an image, but the best bet is to use a Dockerfile.

  2. docker run -p 5000:8000 image will expose port 8000 in the container as port 5000 on the host.

  3. Yes, it will be slower due to the boot2docker VM. It would not be slower if you were running on a Linux host. The advantage is that zeromq is now running in an isolated container with all its dependencies.