cppzmq
cppzmq copied to clipboard
Example doesn't compile
When trying to compile the provided example:
[bart@samadhi zmqtest]$ g++ --std=c++17 main.cc
main.cc: In function ‘int main()’:
main.cc:9:19: error: ‘buffer’ is not a member of ‘zmq’
sock.send(zmq::buffer(m), zmq::send_flags::dontwait);
^~~~~~
main.cc:9:35: error: ‘zmq::send_flags’ has not been declared
sock.send(zmq::buffer(m), zmq::send_flags::dontwait);
Hi @louwers , what gcc version?
@kurdybacha gcc/g++ 9.1.0
I cannot reproduce this with gcc 9.1.1. Are you sure the include path is correct, and you are using the matching version of zmq.hpp?
What would be the matching version? I experience the same problem. I am quite new to C++, so instead of compiling (and according to the docs installing the compiled artifacts to my system) I tried to use the C++ bindings shipped by the Arch Linux package manager. They are supposed to be version 4.3.1.
community/zeromq 4.3.1-2
Fast messaging system built on sockets. C and C++ bindings. aka 0MQ, ZMQ.
It does find the installed bindings (before installing the package it complained that zmq.hpp was missing), but gives the exact error message from the initial post.
Just checked the code files a bit. Indeed, the Arch provided header does not include send_flags
.
It's between these two commits that it was added:
- https://github.com/zeromq/cppzmq/blob/95d519fade9c43419f6fb4ade4d390c483dacf64/zmq.hpp
- https://github.com/zeromq/cppzmq/blob/0ce8ef06d543288fa092745e399e914c1067a895/zmq.hpp
This would make sense, because between the two commits linked above the example code was added. According to the commit history, I'd say that the code example should run with version 4.4.1.
This error also occurs when not specifying the version of c++ to the compiler. Adding -std=c++17 solved the issue for me.