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

5

14

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?

Homogenous answered 24/4, 2013 at 2:13 Comment(3)
How do you compile the c++ code?Phoenicia
I did the C like this - gcc actualApp.c -lzmqHomogenous
I was trying for c++ - g++ actualApp.cpp -lzmqHomogenous
H
7

I moved the file zmq.hpp to /usr/local/include where zmq.h was also there

Homogenous answered 24/4, 2013 at 3:5 Comment(0)
A
5

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
Anastase answered 27/1, 2014 at 18:27 Comment(1)
Why is the .hpp header not included in the tarball?Belia
W
3

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

Wailful answered 24/4, 2013 at 18:11 Comment(1)
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 asyncserverStruble
N
2

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.
Nowak answered 13/9, 2019 at 5:45 Comment(0)
A
1

Add /usr/local/include to your search path

Alli answered 3/6, 2015 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.