簡體   English   中英

如何在Mac OS X上安裝ZeroMQ的C ++綁定?

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

g++ actualApp.cpp -lzmq 

我明白了

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

對於

//
//  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;
}

我已經安裝zeromq在Mac OS X這樣的- ./configuremakemake install

我可以使用-lzmq標志編譯C示例而不會出錯。

我應該如何使用https://github.com/zeromq/cppzmq中的這個C ++ .hpp頭文件?

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

我應該如何使用這個.hpp https://github.com/zeromq/cppzmq文件?

  1. 從上面的鏈接下載CPP綁定(這只是zmq.hpp頭文件)。
  2. 確保在編譯時包含此頭文件。 例如:g ++ yourfile.cpp -I(zmq.hpp的路徑)-lzmq

如果libzmq.so位於另一個文件夾中,則沒有提供包含文件和lib文件夾的路徑。 你需要使用

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

您可能還想給-o outFileName除非您希望將可執行文件命名為a.out

將/ usr / local / include添加到您的搜索路徑

我的配方使用Homebrew(2.1.11)和Xcode(10.3)。

第1步

從Homebrew安裝ZMQ(4.3.2)

brew install zeromq

第2步

克隆來自GitHub的cppzmq

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

第3步:可選

構建並測試cppzmq。

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

第四步

設置Xcode項目。

  1. cppzmp/zmq.hpp復制到/usr/local/include
  2. /usr/local/include添加到Build Settings Header Search Path
  3. 找出合適的標志: pkg-config --libs libzmq 將結果放入Build Settings Other Linker Flags
  4. #include <zmq.hpp>添加到源文件中。
  5. 構建您的Xcode項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM