I am using Mac, and i use homebrew to install zeromq. I want to use zeromq for my application. I tried to compile zmq.hpp https://github.com/zeromq/cppzmq/blob/master/zmq.hpp with
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;
}
but it failed. The error shows
"frameworks/zmq/zmq.hpp:377:35: error: expected ';' at end of declaration list socket_t (const socket_t&) ZMQ_DELETED_FUNCTION; ^ ; frameworks/zmq/zmq.hpp:379:42: error: expected ';' at end of declaration list void operator = (const socket_t&) ZMQ_DELETED_FUNCTION;"
Why is this happened? The zmq.hpp code does not contain any errors. Please help.
Finally I do this and it worked.
#if __has_feature(cxx_deleted_functions)
#define ZMQ_DELETED_FUNCTION = delete
#else
#define ZMQ_DELETED_FUNCTION
#endif
Thanks a lot. Audrey.
The macro
ZMQ_DELETED_FUNCTION
was apparently introduced to provide conditional support for such C++11 feature as "deleted functions" (= delete
). Your compiler does not seem to support that C++11 feature. Hence the error.By design, the
zmq.hpp
attempts to set this macro automatically, by analyzing the compiler version and defining the macro accordingly. It is possible that this automatic detection is being too optimistic. However, it is also possible that your compiler actually supports that feature, you just forgot to turn it on in the compiler settings.BTW, I'm looking at the Clang section of the code that defines the macro
and it looks broken to me. If the compiler does not support
cxx_deleted_functions
feature, then macroZMQ_DELETED_FUNCTION
remains undefined (instead of being defined as empty). This is wrong.Are you using Clang? If so, this could actually be the reason for your error. In that case the error can be fixed by pre-defining
ZMQ_DELETED_FUNCTION
as an empty macro, either as a global macro definition or in the source code before includingzmq.hpp
.