Reputation: 2735
I am using zeromq api for my application and having below indicated link problems. I have installed both zeromq and czmq tar ball to my ubuntu 12.10 system and verified that the necessary header files (e.g. zmq.h)are present under /usr/local/include. Could you please tell me why I am getting these link problems? What would be possible solution. I also installed zmq c++ bindings (zmq.hpp).
/XXXX.cpp:92: undefined reference to `zmq_poll'
CMakeFiles/dummy.dir/__/xxx_api/TheQueue.cpp.o: In function`zmq::error_t::error_t()':
/usr/local/include/zmq.hpp:76: undefined reference to `zmq_errno'
CMakeFiles/dummy.dir/__/xxx_api/TheQueue.cpp.o: In function `zmq::error_t::what() const':
/usr/local/include/zmq.hpp:80: undefined reference to `zmq_strerror'
CMakeFiles/dummy.dir/__/xxx/TheQueue.cpp.o: In function`zmq::context_t::context_t(int)':
/usr/local/include/zmq.hpp:241: undefined reference to `zmq_init'
CMakeFiles/dummy.dir/__/control_api/TheQueue.cpp.o: In function `zmq::context_t::close()':
/usr/local/include/zmq.hpp:267: undefined reference to `zmq_term'
CMakeFiles/dummy.dir/__/xxx_api/TheQueue.cpp.o: In function `zmq::socket_t::socket_t(zmq::context_t&, int)':
collect2: error: ld returned 1 exit status
make[2]: *** [/xxx/build_output/dummy] Error 1
make[1]: *** [/xxx/CMakeFiles/dummy.dir/all] Error 2
Upvotes: 2
Views: 5915
Reputation: 1783
The following example works for me:
Here I have my file, containing the following:
#include "cppzmq/zmq.hpp"
#include <string>
#include <iostream>
int main ()
{
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REQ);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect ("tcp://localhost:5555");
// Do 10 requests, waiting each time for a response
for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
zmq::message_t request (6);
memcpy ((void *) request.data (), "Hello", 5);
std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
socket.send (request);
// Get the reply.
zmq::message_t reply;
socket.recv (&reply);
std::cout << "Received World " << request_nbr << std::endl;
}
return 0;
}
Then here I have the following command, which compiles it:
g++ test.cpp -o test -lzmq
To make zmq work on my linux machine, I simply downloaded zeromq as a tarball (for unix/linux) from their site. I then ran
make && make install
Upvotes: 5