如何在Mac OS X上安装ZeroMQ的C++绑定?

14 c++ macos zeromq

上

g++ actualApp.cpp -lzmq 
Run Code Online (Sandbox Code Playgroud)

我明白了

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
Run Code Online (Sandbox Code Playgroud)

对于

//
//  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;
}
Run Code Online (Sandbox Code Playgroud)

我已经安装zeromq在Mac OS X这样的- ,./configure,.makemake install

我可以使用-lzmq标志编译C示例而不会出错.

我应该如何使用https://github.com/zeromq/cppzmq中的这个C++ .hpp头文件?

小智 7

我将文件zmq.hpp移动到/ usr/local/include,其中zmq.h也在那里


jay*_*dev 5

我应该如何使用此.hpp https://github.com/zeromq/cppzmq文件?

  1. 从上面的链接下载CPP绑定(只是zmq.hpp头文件)。
  2. 确保在编译时包括此头文件。例如:g ++ yourfile.cpp -I(zmq.hpp的路径)-lzmq