简体   繁体   English

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

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

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 . 我已经安装zeromq在Mac OS X这样的- ./configuremakemake install

I can compile the C examples without errors using the -lzmq flag. 我可以使用-lzmq标志编译C示例而不会出错。

How should I use this C++ .hpp header from https://github.com/zeromq/cppzmq ? 我应该如何使用https://github.com/zeromq/cppzmq中的这个C ++ .hpp头文件?

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

How should I use this .hpp https://github.com/zeromq/cppzmq file? 我应该如何使用这个.hpp https://github.com/zeromq/cppzmq文件?

  1. Download the CPP binding (which is just zmq.hpp header file) from the above link. 从上面的链接下载CPP绑定(这只是zmq.hpp头文件)。
  2. Make sure to include this header file while compiling. 确保在编译时包含此头文件。 ex: g++ yourfile.cpp -I(path to zmq.hpp) -lzmq 例如:g ++ yourfile.cpp -I(zmq.hpp的路径)-lzmq

You have not provided a path to the include files and the lib folder if libzmq.so is in another folder. 如果libzmq.so位于另一个文件夹中,则没有提供包含文件和lib文件夹的路径。 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 您可能还想给-o outFileName除非您希望将可执行文件命名为a.out

将/ usr / local / include添加到您的搜索路径

My recipe using Homebrew (2.1.11) with Xcode (10.3). 我的配方使用Homebrew(2.1.11)和Xcode(10.3)。

Step 1 第1步

Install ZMQ (4.3.2) from Homebrew 从Homebrew安装ZMQ(4.3.2)

brew install zeromq

Step 2 第2步

Clone cppzmq from GitHub 克隆来自GitHub的cppzmq

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

Step 3: Optional 第3步:可选

Build and test cppzmq. 构建并测试cppzmq。

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

Step 4 第四步

Set up Xcode project. 设置Xcode项目。

  1. Copy cppzmp/zmq.hpp to /usr/local/include cppzmp/zmq.hpp复制到/usr/local/include
  2. Add /usr/local/include to Header Search Path of Build Settings /usr/local/include添加到Build Settings Header Search Path
  3. Find out proper flags: pkg-config --libs libzmq . 找出合适的标志: pkg-config --libs libzmq Put the result into Other Linker Flags of Build Settings 将结果放入Build Settings Other Linker Flags
  4. Add #include <zmq.hpp> to your source file. #include <zmq.hpp>添加到源文件中。
  5. Build your Xcode project. 构建您的Xcode项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM