How to install the C++ binding for ZeroMQ on Mac OS X?

12,992

Solution 1

How should I use this .hpp https://github.com/zeromq/cppzmq file?

  1. Download the CPP binding (which is just zmq.hpp header file) from the above link.
  2. Make sure to include this header file while compiling. ex: g++ yourfile.cpp -I(path to zmq.hpp) -lzmq

Solution 2

You have not provided a path to the include files and the lib folder if libzmq.so is in another folder. You need to use

g++ actualApp.cpp -I$(Path to ZMQ include files) -L$(Path to ZMQ library files) -lzmq

You probably also want to give -o outFileName unless you want your executable to be named a.out

Solution 3

My recipe using Homebrew (2.1.11) with Xcode (10.3).

Step 1

Install ZMQ (4.3.2) from Homebrew

brew install zeromq

Step 2

Clone cppzmq from GitHub

git clone https://github.com/zeromq/cppzmq.git

Step 3: Optional

Build and test cppzmq.

cd /path/to/cppzmq
./ci_build.sh

Step 4

Set up Xcode project.

  1. Copy cppzmp/zmq.hpp to /usr/local/include
  2. Add /usr/local/include to Header Search Path of Build Settings
  3. Find out proper flags: pkg-config --libs libzmq. Put the result into Other Linker Flags of Build Settings
  4. Add #include <zmq.hpp> to your source file.
  5. Build your Xcode project.

Solution 4

Add /usr/local/include to your search path

Share:
12,992

Related videos on Youtube

Mateusz Piotrowski
Author by

Mateusz Piotrowski

goat n. A POSIX-compliant shell movement boosting hack for real ninjas. Also, FreeBSD is an awesome operating system.

Updated on June 04, 2022

Comments

  • Mateusz Piotrowski
    Mateusz Piotrowski almost 2 years

    On

    g++ actualApp.cpp -lzmq 
    

    I get

    actualApp.cpp:6:19: error: zmq.hpp: No such file or directory
    actualApp.cpp: In function ‘int main()’:
    actualApp.cpp:13: error: ‘zmq’ has not been declared
    actualApp.cpp:13: error: expected `;' before ‘context’
    actualApp.cpp:14: error: ‘zmq’ has not been declared
    actualApp.cpp:14: error: expected `;' before ‘socket’
    actualApp.cpp:15: error: ‘socket’ was not declared in this scope
    actualApp.cpp:18: error: ‘zmq’ has not been declared
    actualApp.cpp:18: error: expected `;' before ‘request’
    actualApp.cpp:21: error: ‘request’ was not declared in this scope
    actualApp.cpp:28: error: ‘zmq’ has not been declared
    actualApp.cpp:28: error: expected `;' before ‘reply’
    actualApp.cpp:29: error: ‘reply’ was not declared in this scope
    actualApp.cpp: At global scope:
    actualApp.cpp:33: error: expected constructor, destructor, or type conversion at end of input
    

    for

    //
    //  Hello World server in C++
    //  Binds REP socket to tcp://*:5555
    //  Expects "Hello" from client, replies with "World"
    //
    #include <zmq.hpp>
    #include <string>
    #include <iostream>
    #include <unistd.h>
    
    int main () {
        //  Prepare our context and socket
        zmq::context_t context (1);
        zmq::socket_t socket (context, ZMQ_REP);
        socket.bind ("tcp://*:5555");
    
        while (true) {
            zmq::message_t request;
    
            //  Wait for next request from client
            socket.recv (&request);
            std::cout << "Received Hello" << std::endl;
    
            //  Do some 'work'
            sleep (1);
    
            //  Send reply back to client
            zmq::message_t reply (5);
            memcpy ((void *) reply.data (), "World", 5);
            socket.send (reply);
        }
        return 0;
    }
    

    I have installed zeromq on Mac OS X like this - ./configure, make, make install.

    I can compile the C examples without errors using the -lzmq flag.

    How should I use this C++ .hpp header from https://github.com/zeromq/cppzmq?

  • fIwJlxSzApHEZIl
    fIwJlxSzApHEZIl over 7 years
    I moved both the header and source file to /usr/local/include and it still says 'fatal error: no such file or directory' : g++ asyncserver.cpp -std=c++11 -I/usr/local/include -L/usr/local/include -lzmq -o asyncserver
  • garyp
    garyp about 7 years
    Why is the .hpp header not included in the tarball?