This article is tested against following version / configuration:
- Visual Studio 2012 (V110) Platform Toolset
- Win32
- ZeroMQ 4.0.4
- Runtime Library: Multi-threaded DLL (/MD)
Steps to setup ZeroMQ on a Visual Studio C++ project:
- Download and install ZeroMQ-4.0.4~miru1.0-x86.exe (or newer) from http://zeromq.org/distro:microsoft-windows
- Set ZEROMQ_HOME environment variable to C:\Program Files (x86)\ZeroMQ 4.0.4 (or wherever you installed it to)
- On Visual Studio project configuration, add $(ZEROMQ_HOME)\include to Configuration Properties -> VC++ Directories. Don’t forget to restart Visual Studio so it picks up the new environment variable
- Add $(ZEROMQ_HOME)\lib to Linker -> General -> Additional Library Directories
- Add libzmq-v110-mt-4_0_4.lib to Linker -> Input -> Additional Dependencies
- Get a copy of zmq.hpp from , place this somewhere on your project. This header file references zmq.h located at $(ZEROMQ_HOME)\include
- Once you’ve compiled your executable, place libzmq-v110-mt-4_0_4.dll on the same folder, otherwise ZeroMQ initialisation will cause runtime crash
And finally take a look at some excellent tutorial examples from zeromq.org website to get you started, in particular:
- Ask And Ye Shall Receive: Request – Reply pattern example
- Getting the Message Out: Publisher – Subscriber pattern example
i’m using visual studio 2013 Community..i’m not using ZeroMQ home path, but i place the lib root c: with short folder name avoiding pesky and potential white space problem, the step is the same but for hpp file i placed in include folder where zmq.h reside.
The problem with this is if you’re in a development team and you check your code into source control, you’re forcing people to place ZeroMQ home on the same location. Generally not a good practice.
I have tried your instructions and I seem to be getting the following error. Any help would be appreciated.
Error 1 error LNK2019: unresolved external symbol __imp__zmq_errno referenced in function “public: __thiscall zmq::error_t::error_t(void)” (??0error_t@zmq@@QAE@XZ)
I have tried several thing found on the internet but none seem to fix the issue
some of the solutions I have tried are:
declaring ZMQ_STATIC in the preprocessor directives
using dumpbin to see if the library file contains the methods mentioned in the error
adding the lib path to the input settings of the linker
I have no idea what else i could try
It looked like the linker couldn’t resolve required symbols. This could happen if you specified wrong library include path, of you’ve set ZEROMQ_HOME but haven’t restarted Visual Studio (hence the env var isn’t yet visible)