I'm having a problem trying to use ZeroMQ in my new application. Please note: I have no problem downloading and building ZeroMQ itself. I downloaded the ZeroMQ ZIP file, opened the project/solution file in Visual Studio/C++ 2008 and built the ZeroMQ library just fine. The /lib directory of the ZeroMQ install folder contains the .lib, .dll, and other files, so all is well there as far as I know.
My problem is that I am trying to build a simple project consisting of the HelloWorld server example in the ZeroMQ user guide. I created the following file called helloserver.c.
//
// Hello World server
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <zmq.h>
#include <stdio.h>
#include <string.h>
int main (void)
{
zmq_msg_t request;
zmq_msg_t reply;
void *context = zmq_init (1);
// Socket to talk to clients
void *responder = zmq_socket (context, ZMQ_REP);
zmq_bind (responder, "tcp://*:5555");
while (1) {
// Wait for next request from client
zmq_msg_init (&request);
zmq_recvmsg (responder, &request, 0);
printf ("Received Hello\n");
zmq_msg_close (&request);
// Do some 'work'
Sleep (1);
// Send reply back to client
zmq_msg_init_size (&reply, 5);
memcpy (zmq_msg_data (&reply), "World", 5);
zmq_sendmsg (responder, &reply, 0);
zmq_msg_close (&reply);
}
// We never get here but if we did, this would be how we end
zmq_close (responder);
zmq_term (context);
return 0;
}
I added the ZeroMQ installatiion include directory to the VC++2008 include path (Properties->Configuration Properties->C/C++->General->Additional Include Directories) and I also added the ZeroMQ lib directory to the project:
(Properties->Configuration Properties->C/C++->Code Generation->Runtime Library, selected Multithreaded Debug DLL /MDd).
I tried to build the project. Everything compiles fine butI get a bunch of unresolved externals like this when linking:
1>Linking…
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_term referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_close referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_sendmsg referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_msg_data referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_msg_init_size referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_msg_close referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_recvmsg referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_msg_init referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_bind referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_socket referenced in function _main
1>helloserver.obj : error LNK2019: unresolved external symbol _imp_zmq_init referenced in function _main
1>C:\work\visualc++2008\projects\HelloZMQServer\Debug\HelloZMQServer.exe : fatal error LNK1120: 11 unresolved externals
I tried going back to the Code generation->Runtime library settings and tried changing the library switch to ?MD or /MT but nothing worked, I still get these linker errors.
Please note that when I created helloworld.c I used an empty windows console application project, and the only changes I made were to add the ZeroMQ include and lib directories as indicated above. I have not changed any other default project settings. I'm guessing I'm missing a project setting somewhere.
How can I fix this?
Best Answer
When I got similar errors it was because I was trying to link the 64-bit libraries into a 32-bit project. I had downloaded the wrong version. When I got the right ones, ie x86 instead of x64, it worked.