[英]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这样的- ./configure
, make
, make 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文件?
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项目。
cppzmp/zmq.hpp
to /usr/local/include
将cppzmp/zmq.hpp
复制到/usr/local/include
/usr/local/include
to Header Search Path
of Build Settings
将/usr/local/include
添加到Build Settings
Header Search Path
pkg-config --libs libzmq
. 找出合适的标志: pkg-config --libs libzmq
。 Put the result into Other Linker Flags
of Build Settings
将结果放入Build Settings
Other Linker Flags
中 #include <zmq.hpp>
to your source file. 将#include <zmq.hpp>
添加到源文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.