I am trying to set up a Co-simulation between Matlab / Simulink and an external application using the ZeroMQ library. The example I would like to build upon is described here. Therefore I need a compiled version (.dll) of the libzmq library's source code, which I downloaded from here. To my understanding the header zmq.hpp (from here) can be used directly without further compilation.
Unfortunately, I cannot manage to build the libzmq library, which is where any help would be very much appreciated! The available solutions suggested in some other questions did not work for me (see below).
I am using Windows 10, Visual Studio 2017 Community Edition and CMake 3.18.4.
As I am quite new to the topic it is definitely possible that I made some mistake during the different attempts I made. That is why I will describe in the following what I already tried that DID NOT WORK:
- Going the same way as described in the example (section "Installing ZeroMQ") by opening the Native Tool Command Prompt from Visual Studio (admin mode), navigating to the build folder of libzmq and execute the provided build batch script resulted in the following error
C:\Users\MY_PATH\ZeroMQ\Work\libzmq-master_VS_native_tool\builds\deprecated-msvc\build>build.bat
Start Time: 18.11.2020 14:04:36,82
Building ..\vs201\libzmq.sln
Platform=x86
Configuration=DynDebug
*** ERROR, build terminated early, see: build_ni.log
Stop Time: 18.11.2020 14:04:37,01
Start Time: 18.11.2020 14:04:36,82
with the build_ni.log containing
Microsoft (R)-Build-Engine, Version 15.9.21+g9802d43bc3 fr .NET Framework
Copyright (C) Microsoft Corporation. Alle rights reserved.
MSBUILD : error MSB1009: Project file does not exist.
Switch: ..\vs201\libzmq.sln
The same problem has been encoutered here
Build zeromq on Windows 10 with CMake,
where the author writes that the Visual Studio solutions within libzmq have been deprecated because they are too difficult to maintain. The author managed to build the libzmq library from source using CMake.
2. I also tried to build the library with CMake Version 3.18.4 by using the GUI. In the Configurations I specified Visual Studio 15 2017 as generator and the default platform (Win32). Here is a screenshot of the resulting CMake cache variables:
I post all of them because I am new to CMake and not sure which of them might possibly be responsible for following errors. The resulting output from CMake indicates that there seems to be a problem with sodium and / or libsodium, although I have no clue here if this is needed whatsoever. Here is the output:
The C compiler identification is MSVC 19.16.27044.0
The CXX compiler identification is MSVC 19.16.27044.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
Detected ZMQ Version - 4.3.4
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Not building draft classes and methods
Using builtin sha1
**CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:273 (message):
The package name passed to `find_package_handle_standard_args` (sodium)
does not match the name of the calling package (Sodium). This can lead to
problems in calling code that expects `find_package` result variables
(e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
builds/cmake/Modules/FindSodium.cmake:42 (find_package_handle_standard_args)
CMakeLists.txt:265 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
Could NOT find sodium (missing: SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)
CMake Warning at CMakeLists.txt:275 (message):
libsodium not installed, instead using builtin tweetnacl, you may want to
install libsodium and run cmake again**
Using tweetnacl for CURVE security
Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: 0x0A00
Using polling method in I/O threads: epoll
Including wepoll
Using polling method in zmq_poll(er)_* API: poll
Using 64 bytes alignment for lock-free data structures
Looking for include file windows.h
Looking for include file windows.h - found
Looking for include files winsock2.h, afunix.h
Looking for include files winsock2.h, afunix.h - found
Looking for include file condition_variable
Looking for include file condition_variable - found
Using condition_variable_t implementation: stl11
Looking for WSAStartup
Looking for WSAStartup - found
Looking for UuidCreateSequential
Looking for UuidCreateSequential - found
Looking for GetAdaptersAddresses
Looking for GetAdaptersAddresses - found
Looking for fopen in ws2
Looking for fopen in ws2 - not found
Performing Test HAVE_FLAG_/W3
Performing Test HAVE_FLAG_/W3 - Success
Checking whether noexcept is supported
Performing Test ZMQ_HAVE_NOEXCEPT
Performing Test ZMQ_HAVE_NOEXCEPT - Success
Could NOT find AsciiDoc (missing: ASCIIDOC_EXECUTABLE)
**CMake Warning (dev) at tests/CMakeLists.txt:306 (message):
Test 'test_bind_stream_fuzzer' is not known to CTest.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at tests/CMakeLists.txt:306 (message):
Test 'test_bind_ws_fuzzer' is not known to CTest.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at tests/CMakeLists.txt:306 (message):
Test 'test_connect_stream_fuzzer' is not known to CTest.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at tests/CMakeLists.txt:306 (message):
Test 'test_connect_ws_fuzzer' is not known to CTest.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at tests/CMakeLists.txt:306 (message):
Test 'test_socket_options_fuzzer' is not known to CTest.
This warning is for project developers. Use -Wno-dev to suppress it.**
Configuring done
After generating the Build folder I opened the resulting ZeroMQ.sln in Visual Studio 2017 (with admin rights) and performed the following steps:
- In the solution explorer (including ALL_BUILD, ZERO_CHECK, libzmq ...) I set the folder "libzmq" as startup project
- Start the "Local Windows Debugger"
Here is the output from Visual Studio (I replaced the actual path to the ZeroMQ folder with "MY_PATH"):
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------
1>Checking Build System
2>------ Build started: Project: libzmq, Configuration: Debug Win32 ------
2>Generating NSIS.template.in
2>Building Custom Rule C:/Users/MY_PATH/ZeroMQ/libzmq/CMakeLists.txt
2>precompiled.cpp
2>sha1.c
2>tweetnacl.c
2>wepoll.c
2>address.cpp
2>channel.cpp
2>client.cpp
2>clock.cpp
2>ctx.cpp
2>curve_mechanism_base.cpp
2>curve_client.cpp
2>curve_server.cpp
2>dealer.cpp
2>devpoll.cpp
2>dgram.cpp
2>dist.cpp
2>endpoint.cpp
2>epoll.cpp
2>err.cpp
2>fq.cpp
2>io_object.cpp
2>io_thread.cpp
2>ip.cpp
2>ipc_address.cpp
2>ipc_connecter.cpp
2>ipc_listener.cpp
2>kqueue.cpp
2>lb.cpp
2>mailbox.cpp
2>mailbox_safe.cpp
2>mechanism.cpp
2>mechanism_base.cpp
2>metadata.cpp
2>msg.cpp
2>mtrie.cpp
2>norm_engine.cpp
2>object.cpp
2>options.cpp
2>own.cpp
2>null_mechanism.cpp
2>pair.cpp
2>peer.cpp
2>pgm_receiver.cpp
2>pgm_sender.cpp
2>pgm_socket.cpp
2>pipe.cpp
2>plain_client.cpp
2>plain_server.cpp
2>poll.cpp
2>poller_base.cpp
2>polling_util.cpp
2>pollset.cpp
2>proxy.cpp
2>pub.cpp
2>pull.cpp
2>push.cpp
2>random.cpp
2>raw_encoder.cpp
2>raw_decoder.cpp
2>raw_engine.cpp
2>reaper.cpp
2>rep.cpp
2>req.cpp
2>router.cpp
2>select.cpp
2>server.cpp
2>session_base.cpp
2>signaler.cpp
2>socket_base.cpp
2>socks.cpp
2>socks_connecter.cpp
2>stream.cpp
2>stream_engine_base.cpp
2>sub.cpp
2>tcp.cpp
2>tcp_address.cpp
2>tcp_connecter.cpp
2>tcp_listener.cpp
2>thread.cpp
2>trie.cpp
2>radix_tree.cpp
2>v1_decoder.cpp
2>v1_encoder.cpp
2>v2_decoder.cpp
2>v2_encoder.cpp
2>v3_1_encoder.cpp
2>xpub.cpp
2>xsub.cpp
2>zmq.cpp
2>zmq_utils.cpp
2>decoder_allocators.cpp
2>socket_poller.cpp
2>timers.cpp
2>radio.cpp
2>dish.cpp
2>udp_engine.cpp
2>udp_address.cpp
2>scatter.cpp
2>gather.cpp
2>ip_resolver.cpp
2>zap_client.cpp
2>zmtp_engine.cpp
2>stream_connecter_base.cpp
2>stream_listener_base.cpp
2> Creating library C:/Users/MY_PATH/ZeroMQ/libzmq/Build/lib/Debug/libzmq-v141-mt-gd-4_3_4.lib and object C:/Users/MY_PATH/ZeroMQ/libzmq/Build/lib/Debug/libzmq-v141-mt-gd-4_3_4.exp
2>libzmq.vcxproj -> C:\Users\MY_PATH\ZeroMQ\libzmq\Build\bin\Debug\libzmq-v141-mt-gd-4_3_4.dll
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
At the end I received the following error from Visual Studio: Error message from Visual Studio
It says:
Unable to start program
'C:\Users\MY_PATH\ZeroMQ\libzmq\Build\lib\Debug\libzmq-v141-mt-gd-4_3_4.dll'.
C:\Users\MY_PATH\ZeroMQ\libzmq\Build\lib\Debug\libzmq-v141-mt-gd-4_3_4.dll is not a valid Win32 application
This leads me to the assumption that the attempt to correctly build the ZeroMQ library failed.
- The last thing I tried was a suggestion from a comment in Build zeromq on Windows 10 with CMake:
"VS2015 Toolbar -> Open -> CMake -> ZMQ folder
Toolbar -> CMake -> Cache -> Generate -> ZeroMQ
Toolbar -> CMake -> Install -> ZeroMQ
You can find builds in /Users/UserName/CMakeBuilds/..."
When I tried this I received some warnings and an error that you can find here, from which I don't know what to do with it. Basically it refers to lines 275 and 306 of CMakeLists.txtand says that libsodium is not installed and the error says:
Cannot open compiler intermediate file 'c\users\MY_USER\cmakebuilds\6d974590-78c5-853d-bf52-b3f968050d60\build\x64-Debug (default)\precompiled.pch': Permission denied
multiple rules generate precompiled.hpp. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]
Following the steps from the accepted answer in this post Getting ZeroMQ up and running on Windows 10 also results in errors and no build folder is added to the user's CMakeBuilds subfolder.