![](/img/trans.png)
[英]How to install ZeroMQ on Mac OS X 10.9 for use in a C/C++ program
[英]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這樣的- ./configure
, make
, make install
。
我可以使用-lzmq
標志編譯C示例而不會出錯。
我應該如何使用https://github.com/zeromq/cppzmq中的這個C ++ .hpp
頭文件?
我將文件zmq.hpp移動到/ usr / local / include,其中zmq.h也在那里
我應該如何使用這個.hpp https://github.com/zeromq/cppzmq文件?
如果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項目。
cppzmp/zmq.hpp
復制到/usr/local/include
/usr/local/include
添加到Build Settings
Header Search Path
pkg-config --libs libzmq
。 將結果放入Build Settings
Other Linker Flags
中 #include <zmq.hpp>
添加到源文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.