Hot questions for Using ZeroMQ in visual studio

Top 10 C/C++ Open Source / ZeroMQ / visual studio

Question:

While my primary domain of expertise is not Visual Studio 2015 setup / project configuration, I have experienced troubles on loading / configuring ZeroMQ project.

How to proceed correctly on loading a ZeroMQ Project?

Observed errors:

  • current build on github and even old "stable" versions cause cmake errors
  • ZeroMQ Installer does not support Visual Studio v14

Instructions would be awesome, as it seems that there is no other source of documentation for this situation on the internet.


Answer:

Had the same problem a while ago. Here is what I did to solve this:

Download the right ZMQ version

The "download link" provided on the ZMQ website seems outdated. To really get the current version you would have to use Git:

git clone https://github.com/zeromq/libzmq.git

Build with Visual Studio 2015

The repository comes with a pre-build Visual Studio project. You can find it in ...\libzmq\builds\msvc. To build for Visual Studio 2015 cd into vs2015 and open libzmq.sln.

You can choose if you want to compile static or dynamic libraries: DynRelease or StaticRelease for either Win32 or x64.

After that, run Build > Build solution to compile everything.


Setup project to use compiled libraries

After you created your project, go to the project's properties:

C++ > General > Additional Include Directories should point to the include path of the repository. If you want to use C++ style some additional files have to be placed in this directory. Alternatively you can take a look at https://github.com/zeromq/zmqpp.

Linker > General > Additional Library Directories should point to the built libraries. They should be located at ...\libzmq\bin\x64\Release\v140\dynamic\.

Linker > Input > Additional Dependencies should contain the name of the library you want to use. The default should be libzmq.lib, otherwise you will find the name in the bin directory.

The program depends on the libzmq.dll file you just built. This file has to be placed within your project's build directory. To achieve this, you can add the following command to Build Events > Post-Build Event > Command Line:

copy /Y "...\libzmq\bin\x64\Release\v140\dynamic\libzmq.dll" "$(OutDir)"

This will copy the .dll file to the destination directory on every build if it's missing.


Hope this helps =)

Question:

When trying to install the netmq vis nuget, I get the following error:

Could not install package 'AsyncIO 0.1.18'. You are trying to install this package
 into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111',
 but the package does not contain any assembly references or content files that
 are compatible with that framework. For more information, contact the package author.

The problem is that netmq depends on AsyncIO. when installing it, nuget find that the assembly is not compatible with .Net 4.5.

so nuget fail in installing AsyncIO, and then failed in installing netmq.

So I downloaded the AsyncIO Source from Github and build it locally with .Net 4.5.

After that and added the dll of AsyncIO built locally as a reference for my project.

Theoretically, NetMQ should be successfully installed with nuget. because I added the needed reference to AsyncIO.

But when trying to reinstall NetMQ, I get the same error:

Could not install package 'AsyncIO 0.1.18'. You are trying to install this package
 into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111',
 but the package does not contain any assembly references or content files that
 are compatible with that framework. For more information, contact the package author.

and nuget did not detect that I added 'AsyncIO 0.1.18' in my project.

How to let nuget detect that I added this reference in my project?


Answer:

Have a look here:

.NET Portable profiles

Profile111 is a combination of:

  • .NET Framework 4.5
  • Windows 8.0
  • Windows Phone 8.1

or in other words: portable-net45+netcore45+wpa81

So your project into which you are trying to append the NuGet targets Windows Phone 8.1 and other 2 platforms, I mention this one as the most restrictive.

Now let's have a look at the named NuGet package's source:

 <ProjectGuid>{3830B7A3-0225-4FDA-B155-E085E183650C}</ProjectGuid> 
 <OutputType>Library</OutputType> 
 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 
 <TargetFrameworkProfile> 
 </TargetFrameworkProfile> 

What do we have here? We can see that the project is not a PCL. It is targeting full .NET 4.0 framework which is not available on Windows Phone 8.1. And your library does target Windows Phone 8.1. See the problem?

You say that if you compile the AsyncIO targeting .NET 4.5 than you can successfully append it into your project as a reference? That's not altogether true. I mean you can append a reference to it but you cannot use it. You will see that when you try to call something from that reference.

In order to use AsyncIO from you PCL will have to build AsyncIO as a PCL targeting the same or more restrictive set of platforms. Try creating a PCL project targeting Profile111 and try compiling the AsyncIO code with it (just link the original AsyncIO source files (*.cs) into this new AsyncIO_PCL project). If you are lucky enough and the code of AsyncIO is really compatible you will be able to use that library.

Here are your steps:

  1. Create a new project (named AsyncIO_PCL) of type PCL class library.
  2. Pick the Profile111 platform set i.e.
    • .NET Framework 4.5
    • Windows 8.0
    • Windows Phone 8.1
  3. Link all the .cs files from the original AsyncIO project save one (AssemblyInfo.cs) into the new AsyncIO_PCL project.
  4. Set the output assembly name to the same as in original AsyncIO project.
  5. Try building the project.

Your ability to build the AsyncIO as a PCL with the required set of supported platforms depends on AsyncIO code i.e. which API is used inside and if that API is supported by all the three platforms you are targeting.

Question:

I am attempting to use the static library of ZeroMQ in Visual Studio 2015. I generated it by cloning the git repository, changing the windows.hpp include in fd.hpp from #include <windows.hpp> to #include "windows.hpp", putting libsodium in the right place, and then batch building everything in the vs2015 solution.

In the program I am trying to use ZeroMQ in I included the ZeroMQ include directory, included the ZeroMQ release static directory (libzmq\bin\Win32\Release\v140\static), added libzqm.lib as an additional dependency, defined ZMQ_STATIC and _CRT_SECURE_NO_WARNINGS for some other things I am doing in my program, and changed the runtime library to Multi-threaded /MT.

When I try to compile at this point I get these errors:

1>------ Build started: Project: HttpServer, Configuration: Release Win32 ------
1>  main.cpp
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libzmq.lib(socket_poller.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(socket_poller.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__select@20
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol __imp__WSAStartup@8
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol __imp__WSACleanup@0
1>libzmq.lib(socks_connecter.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(ip.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(tcp.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(tcp_connecter.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(zmq.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(err.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(socket_poller.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol __imp__htonl@4
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__htonl@4
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libzmq.lib(udp_address.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libzmq.lib(stream_engine.obj) : error LNK2001: unresolved external symbol __imp__htons@4
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
1>libzmq.lib(stream_engine.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__ntohs@4
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol _if_nametoindex@4
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol __imp__getaddrinfo@16
1>libzmq.lib(socks.obj) : error LNK2001: unresolved external symbol __imp__getaddrinfo@16
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol __imp__freeaddrinfo@4
1>libzmq.lib(socks.obj) : error LNK2001: unresolved external symbol __imp__freeaddrinfo@4
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol __imp__getnameinfo@28
1>libzmq.lib(ip.obj) : error LNK2001: unresolved external symbol __imp__getnameinfo@28
1>libzmq.lib(tcp_address.obj) : error LNK2001: unresolved external symbol _in6addr_any
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__getsockname@12
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__getsockname@12
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__getsockname@12
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__getsockopt@20
1>libzmq.lib(tcp_connecter.obj) : error LNK2001: unresolved external symbol __imp__getsockopt@20
1>libzmq.lib(socks_connecter.obj) : error LNK2001: unresolved external symbol __imp__getsockopt@20
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__WSACloseEvent@4
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__WSACreateEvent@0
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__WSAEventSelect@12
1>libzmq.lib(select.obj) : error LNK2001: unresolved external symbol __imp__WSAWaitForMultipleEvents@20
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__accept@12
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__accept@12
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libzmq.lib(tcp_connecter.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libzmq.lib(socks_connecter.obj) : error LNK2001: unresolved external symbol __imp__bind@12
1>libzmq.lib(socks_connecter.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libzmq.lib(stream_engine.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libzmq.lib(tcp_connecter.obj) : error LNK2001: unresolved external symbol __imp__closesocket@4
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__connect@12
1>libzmq.lib(tcp_connecter.obj) : error LNK2001: unresolved external symbol __imp__connect@12
1>libzmq.lib(socks_connecter.obj) : error LNK2001: unresolved external symbol __imp__connect@12
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__listen@8
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__listen@8
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__recv@16
1>libzmq.lib(tcp.obj) : error LNK2001: unresolved external symbol __imp__recv@16
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__send@16
1>libzmq.lib(tcp.obj) : error LNK2001: unresolved external symbol __imp__send@16
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
1>libzmq.lib(signaler.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
1>libzmq.lib(tcp_listener.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
1>libzmq.lib(ip.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
1>libzmq.lib(tcp.obj) : error LNK2001: unresolved external symbol __imp__setsockopt@20
1>libzmq.lib(udp_address.obj) : error LNK2001: unresolved external symbol __imp__inet_addr@4
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__inet_addr@4
1>libzmq.lib(ip.obj) : error LNK2001: unresolved external symbol __imp__ioctlsocket@12
1>libzmq.lib(ip.obj) : error LNK2001: unresolved external symbol __imp__getpeername@12
1>libzmq.lib(ip.obj) : error LNK2001: unresolved external symbol __imp__socket@12
1>libzmq.lib(tcp.obj) : error LNK2001: unresolved external symbol __imp__WSAIoctl@36
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__inet_ntoa@4
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__recvfrom@24
1>libzmq.lib(udp_engine.obj) : error LNK2001: unresolved external symbol __imp__sendto@24
1>H:\Programming\c++\HttpServer\Release\HttpServer.exe : fatal error LNK1120: 35 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What confuses me is that when I include the ZeroMQ release dynamic directory (libzmq\bin\Win32\Release\v140\dynamic), which contains the dll, it compiles just fine. However, when I try to run my program it requires the dll to run. This is what I am trying to avoid by using the static library of ZeroMQ. I'm at a loss as to what to do now.

EDIT

I do not believe my question is related to this because it appears to me that the static .lib is referencing stuff in the .dll which means that I need to include the .dll with my program, doesn't this mean I am not really statically linking the library? Has anyone been able to use ZeroMQ on windows without needing a dll?


Answer:

Looks like I needed to link to these libraries as well.

wsock32.lib
ws2_32.lib
Iphlpapi.lib

Question:

I am trying from past 4 days to get Zeromq working on my Windows machine but nothings seems to go my way.

I followed given steps and solved few dependcy issues.

I have build libzmq,czmq,libsodium successfully.

I used cmake 3.12 to configure and VS2015 SDK 8.1 to build solution.

I was able to run czmq_selftest.exe however it failed for few things and thats different issue.

But when I try to run basic program myapp.c

#include <czmq.h>
int main (void) {
 zsock_t *publisher = zsock_new (ZMQ_PUB);
 zsock_set_curve_server (publisher, true);
 puts ("Hello, Curve!");
 zsock_destroy(&publisher);
 return 0;
}

I see this missing library issue , I tried given link method-

 gcc myapp.c -o myapp -lczmq -lzmq

But nothing is working it would be really helpful if someone can provide some solution.

Here is other info -

OS - Windows 10
Cmake - 3.13.2
Visual Studio 2015, SDK 8.1
libzmq 4.3.0
czmq 4.1.1

Source: https://github.com/zeromq/czmq

More information-

My system-

C:\Users\P\go\src\github.com\zeromq\czmq\include

contains all the libraries.

My program is in -

C:\Users\P\go\src\github.com\zeromq\czmq\examples\security

Thanks


Answer:

The compiler can't keep track of all libraries that a user might have installed on a system by itself. You have to tell the compiler where it can find things like header files or linker-libraries.

To tell the compiler to add a path to the list it uses for searching for header file, use the -I (upper-case i) option.

To tell the linker to add a path to the list it uses to search for linker-libraries use the -L option.

Considering the paths you mention in your question and comments you need to add both -I../../include and -L../../Debug.

That is, your complete command should look something like

gcc myapp.c -o myapp -I../../include -L../../Debug -lczmq -lzmq

Of course, that requires your to be in the directory C:\Users\P\go\src\github.com\zeromq\czmq\examples\security as you say.

Question:

Anyone out there successfully building/using ZeroMQ under Windows (MSVC)?

I'm trying to build/use the current master in GitHub (https://github.com/zeromq/libzmq) which has Visual Studio projects as well as CMake files. I've built the CMake project (after fixing some issues in the MSVC specific stuff) which also builds all the tests but the tests fail the same way my simple test program does.

The first call to WinSock select() always results in WSAENOTSOCK and the app bails. I've now tried this on a 64bit Win7 and Win8 machines with both VS2010 and VS2013 for debug and release builds with no luck :(

I get similar aborts when trying to build against the pre-built binaries on the ZeroMQ site or building my own with the included Visual Studio project directories they include in the repository.


Answer:

After further investigation and a few hints from the mailing list the moral of the story is ZeroMQ, Windows and RealVNC don't mix.

If port 5905 is in use by anything else then ZeroMQ will crash under Windows (you can use netstat -a -b to check).

Although as a more general observation, ZeroMQ relying on hard coded ports to be free and not gracefully handling this case is less than ideal.

http://lists.zeromq.org/pipermail/zeromq-dev/2015-August/029451.html