This may be a Visual Studio question more than anything else...
I'm trying to build a 0MQ C++ example using VS10 and ZeroMQ 2.2.0.
I downloaded the windows sources and tried to follow these instructions in order to build 0MQ statically. Specifically:
- Switched to Release
- For all 7 projects in the solution:
- set
General\Configuration Type
toStatic library (.lib)
- set
C/C++\Code Generation\Runtime Library
toMulti-threaded (/MT)
- added
ZMQ_STATIC
toC/C++\Preprocessor\Preprocessor Definitions
- set
- Updated
zmq.h
andzmq_utils.h
so that if_MSC_VER
andZMQ_STATIC
are defined thenDLL_EXPORT
will also be defined
At this point 0MQ seems to build well.
- Created an empty console project:
- switched to Release
- added a single cpp file with the example linked above
- changed
random
torand
,srandom
tosrand
andsnprintf
to_snprintf
- changed
- set
C/C++\Code Generation\Runtime Library
toMulti-threaded (/MT)
- added
...\zeromq-2.2.0\include
folder toC/C++\General\Additional Include Directories
- added
...\zeromq-2.2.0\builds\msvc\Release\*.lib
toLinker\Input\Additional Dependencies
However I still receive the following linking errors:
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_bind
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_close
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_errno
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_init
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_data
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_strerror
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_socket
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_init_size
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_term
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_close
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_send
What have I missed?
You should add
ZMQ_STATIC
toC/C++\Preprocessor\Preprocessor Definitions
in your "empty console project" too. Otherwise, when you compile your application,ZMQ_EXPORT
inzmq.h
is defined as__declspec(dllimport)
, and as a result, MSVC looks for__imp__zmq_*
symbols instead ofzmq_*
I had similar errors - not when trying to statically link, but just trying to create a ZMQ project and link the .lib 'stubs' for the dll.
In my case 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.
Is the static linking very important to you? If not, you can try out the second answer by elnino_9 here. Elaborating elnino_9's answer:
Some comments:
publisher.bind("ipc://weather.ipc");
) will cause an exception. As explained here (though in fine-print), the Inter-Process Transport is not supported on Windows.EDIT
I think the answer to my first comment can be found in MSDN: