[zeromq-dev] Static linking issue on Win32

Dave Goodall dave.goodall at gmail.com
Fri Sep 2 22:45:38 CEST 2011

The last post on this subject was September 2010.

I am a newbie to 0mq and would like to know if the issues discussed on that
thread have been resolved in 3.0?

I have been able to successfully compile and run the 3.0.1 hwserver and
hwclient examples with MSVC 2010 using libzmq.dll, but i have not

been able to build a static libzmq.lib that will link without LNK2001

I’m appending a summary of the configuration process I’ve gone through to
get to this point. It would clearly be valuable to developers

deploying 0mq on the Windows platform if the configuration for static builds
was simpler.

I don't think a complete plug-n-play experience is  either necessary or
desirable. Any accomodations needed to make 0mq more Windows friendly

in this respect that can be done in a clean generic way are sufficient.  Any
other M'soft/Windows/VCC compiler specific configurations can

and should be handled in documentation along the lines of the following (but
hopefully shorter!).



Compiling 0mq examples with Microsoft Visual C++ 2010

Dave Goodall  2011 09 02

1.    Pre-requisites to build on Windows

-    You need Microsoft Visual C++ 2008 or newer.

2.    Building the libzmq library for static linking

 Unpack the .zip source archive.

 In Visual C++ open the solution c:\technology

The default build is ‘Debug’.  Use Configuration Manager to change that to
‘Release’ to build release.

The default is to build dlls NOT static libraries! The default
‘out-of-the-box’ build will generate a dynamic link library into

...\zeromq-3.0.1\lib\libzmq.dll  (654,336 bytes).

To build static debug and release libraries:

Per http://lists.zeromq.org/pipermail/zeromq-dev/2010-November/007756.html

-    Edit ...\zeromq-3.0.1\include\zmq.h

-    Replace
/*  Win32 needs special handling for DLL exports   */
#if defined _WIN32
#   if defined DLL_EXPORT
#       define ZMQ_EXPORT __declspec(dllexport)
#   else
#       define ZMQ_EXPORT __declspec(dllimport)
#   endif
#   define ZMQ_EXPORT

-    With
#if defined _MSC_VER
#   if defined ZMQ_STATIC
#       define DLL_EXPORT
#   endif
#   if defined DLL_EXPORT
#       define ZMQ_EXPORT __declspec(dllexport)
#   else
#       define ZMQ_EXPORT __declspec(dllimport)
#   endif
#   define ZMQ_EXPORT

For each of the 7 projects in the solution :  libzmq, inproc_lat,
inproc_thr, local_lat, local_thr, remote_lat, remote_thr, right click on

the project   then on ‘Properties’ and under:

-    Configuration Properties | General  | ‘Configuration Type’  change the
default ‘Dynamic Library (.dll) to  ‘Static Library (.lib)’

-    Configuration Properties | C/C++  | ‘Preprocessor Definitions’  add

-    Build the solution libzmq:

-    Ignore warnings: …\include\zmq.h(48) : warning C4005: 'DLL_EXPORT' :
macro redefinition command-line arguments :see previous

definition of 'DLL_EXPORT'

-    Copy output …\zeromq-3.0.1\builds\msvc\Release\libzmq.lib in the same
folder as libzmq_3.0.1_release.lib.    Library size was 24,234


-    Copy output …\zeromq-3.0.1 builds\msvc\Release\libzmq.lib in the same
folder as libzmq_3.0.1_debug.lib.     Library size was 99999


3.    Setting up projects (eg hwserver) to build examples statically linked
with libzmq_3.0.1_debug | release.lib

-    Create a new empty CONSOLE project.  Note! MSVC 2010 has a very bad
habit of creating a second directory with the same name under the

first!  Check that you only have ONE before continuing!

-    Add existing header zmq.h and existing source hwclient.c  to the
project. Note! MSVC 2010 will let you add source (*.c) files under

the ‘Header Files’ branch, and header (*.h) files under the ‘Source Files’
branch without a murmur.  Check that you have added headers and

source files under the appropriate branch before continuing!

Right click on (for example) the hwserver project and then on ‘Properties’
and under:

-    Configuration Properties | VC++ Directories | Library Directories add
...\zeromq-3.0.1\builds\msvc\Release | Debug; to pull in the static link
libzmq library.

-    Configuration properties | C/C++ | Code Generation | Runtime Library
from ‘Multi-Threaded DLL (/MD)’ to  ‘Multi-Threaded (/MT)’ OR

‘Multi-Threaded Debug ((/MTd)’   depending on whether we’re using the
Release  or Debug version of the libzmq library.

-    Configuration properties | C/C++ | Precompiled Headers set ‘Precompiled
Header’ to ‘Not using precompiled headers’.

-    Configuration properties | C/C++ |Advanced |Compile as C Code.

-    Configuration properties | Linker | Input | Additional Dependencies and
add libzmq_3.0.1_Release.lib

-    Configuration Properties | Linker | System | Subsystem should be set to

-    I compiled my own project and got more link errors, then I Googled
again and added:

4.    Changes to example code  (eg:.  hwserver.c)

-    Change angle brackets in #include <zmq,h> to “zmq.h” (local mangled
-    Comment out   //#include "StdAfx.h"
-    Comment out   //#include "unistd.h"
-    Add #include <WinBase.h>   // Sleep() NOT sleep()
-    Change zmq_recv to zmg_recvmsg (If using version 3.0)
-    Change zmq_send  to zmq_sendmsg  (If using version 3.0)
-    Change on-the-fly variable declarations.  Move the declarations to the
start of the function. For example: void *requester = zmq_socket (context,
ZMQ_REQ); becomes two lines:
-    void * requester
-    Requester = zmq_socket (context, ZMQ_REQ);

[End Document]
I'll have it all figured out by the time we reach the frontier.
What's that?
The frontier
__________________________ The Last Starfighter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110902/ce4f08ab/attachment.htm>

More information about the zeromq-dev mailing list