Hot questions for Using ZeroMQ in failed installation

Top 10 C/C++ Open Source / ZeroMQ / failed installation

Question:

I work on a trading engine where at the time of run, I get the log from the engine.log like the following,

2018_01_02_03_28_20_684 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - no jzmq in java.library.path, sleeping 2 minutes then try again
2018_01_02_03_28_20_697 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_30_20_696 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_30_20_710 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_32_20_697 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_32_20_711 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_34_20_698 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_34_20_712 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_36_20_699 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_36_20_713 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again

I believe the first line tells the main issue,

No jzmq in java.library.path

I followed the setup manual for the ZMQ binding for Java,

cd /root
wget https://github.com/zeromq/jzmq/archive/v3.1.0.tar.gz -O jzmq-3.1.0.tar.gz
tar zxf jzmq-3.1.0.tar.gz
cd jzmq-3.1.0
./autogen.sh
./configure --prefix=/opt/jzmq-3.1.0
nice make
make install

After I load the project, it was required to run the commands in the project root,

root@debian:~# export LD_LIBRARY_PATH=/opt/jzmq-3.1.0/lib

root@debian:~# java -Xss256k -cp /opt/jzmq-3.1.0/share/java/zmq.jar:draglet-common/target/lib/*:draglet-balser/target/lib/*:draglet-engine/target/lib/*:draglet-remote/target/lib/*:draglet-mapu/target/lib/*:draglet-shaba/target/lib/*:draglet-meba/target/lib/* -Dlog4j.configurationFile=draglet-common/src/main/resources/log4j2.xml -DisThreadContextMapInheritable=true com.draglet.batch.Batch draglet.yml

At the time I get outputs like,

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

Tue Jan 02 03:59:17 EST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Is the issue has anything to do with the warning provided in the Intellij terminal? How do I check if the jzmq is in the java.library.path?


Answer:

On OSX I was having a similar problem. I installed ZMQ using these instructions.

The last step says to set library path with -Djava.library.path=/usr/local/lib.

I found it much easier to simply add the path into

~/.bash_profile

for example:

echo "export JAVA_LIBRARY_PATH=$JAVA_LIBRARY_PATH:/usr/local/lib" >> ~/.bash_profile

After restarting Intellij it was able to correctly find libjzmq.

Also it may be a good idea to export the DYLD_LIBRARY_PATH as well if you are planning on doing any C/C++ development.

Simply add

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib"

to

~/.bash_profile.

Question:

I have XAMPP with PHP Version PHP 7.1.13 (cli) (built: Jan 3 2018 20:16:04) ( ZTS MSVC14 (Visual C++ 2015) x86 ).

I want to install the ZeroMQ extension, which

  • I downloaded from here http://pecl.php.net/package/zmq/1.1.3/windows specifically 7.1 Thread Safe (TS) x86
  • moved the php_zmq.dll to the file C:\xampp\php\ext, and
  • wrote extension=php_zmq.dll into the file C:\xampp\php\php.ini,
  • wrote C:\xampp\php\ext in to Windows PATH,

but I still getting this error :

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_zmq.dll' - The specified module could not be found. in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_zmq.dll' - The specified module could not be found. in Unknown on line 0

What could be the problem?


Answer:

I did the same as others suggested, but it still did not work. Then I noticed that there is one more .DLL file in the ZMQ ZIP file: libsodium.dll. When I copied this to the C:\xampp\php directory, it worked.

To summarize: files libsodium.dll and libzmq.dll must be copied to C:\xampp\php directory.

Question:

With vcpkg, after I enabled ZMQ_BUILD_DRAFT_API for both the zeromq and cppzmq. The build fails with the following errors

1>------ Build started: Project: myproj, Configuration: Debug x64 ------
1>my1.cpp
1>my2.cpp
1>my3.cpp
1>my4.cpp
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_new referenced in function "public: __cdecl zmq::poller_t<unsigned __int64>::poller_t<unsigned __int64>(void)" (??0?$poller_t@_K@zmq@@QEAA@XZ)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_destroy referenced in function "public: void __cdecl zmq::poller_t<unsigned __int64>::destroy_poller_t::operator()(void *)" (??Rdestroy_poller_t@?$poller_t@_K@zmq@@QEAAXPEAX@Z)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_add referenced in function "private: void __cdecl zmq::poller_t<unsigned __int64>::add_impl(class zmq::socket_ref,enum zmq::event_flags,unsigned __int64 *)" (?add_impl@?$poller_t@_K@zmq@@AEAAXVsocket_ref@2@W4event_flags@2@PEA_K@Z)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_remove referenced in function "public: void __cdecl zmq::poller_t<unsigned __int64>::remove(class zmq::socket_ref)" (?remove@?$poller_t@_K@zmq@@QEAAXVsocket_ref@2@@Z)
1>my5.obj : error LNK2019: unresolved external symbol __imp_zmq_poller_wait_all referenced in function "public: unsigned __int64 __cdecl zmq::poller_t<unsigned __int64>::wait_all(class std::vector<struct zmq::poller_event<unsigned __int64>,class std::allocator<struct zmq::poller_event<unsigned __int64> > > &,class std::chrono::duration<__int64,struct std::ratio<1,1000> >)" (?wait_all@?$poller_t@_K@zmq@@QEAA_KAEAV?$vector@U?$poller_event@_K@zmq@@V?$allocator@U?$poller_event@_K@zmq@@@std@@@std@@V?$duration@_JU?$ratio@$00$0DOI@@std@@@chrono@4@@Z)
1>G:\build\x64\Debug\myproj.exe : fatal error LNK1120: 5 unresolved externals
1>Done building project "myproj.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is my portfile.cmake for zeromq

include(vcpkg_common_functions)

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO zeromq/libzmq
    REF 8d34332ff2301607df0fc9971a2fbe903c0feb7c
    SHA512 8b3a9b6c4e5236353672b6deb64c94ac79deb116962405f01fe36e2fd8ddc48ec65d88ffc06746ce2e13c93eaeb04e4ba73de8f9d6f2a57a73111765d5ba8ad7
    HEAD_REF master
)

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)

vcpkg_check_features(
    OUT_FEATURE_OPTIONS FEATURE_OPTIONS
    FEATURES
        sodium WITH_LIBSODIUM        
    INVERTED_FEATURES
        websockets-sha1 DISABLE_WS
)

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
    PREFER_NINJA
    OPTIONS
        -DZMQ_BUILD_TESTS=OFF
        -DPOLLER=select
        -DBUILD_STATIC=${BUILD_STATIC}
        -DBUILD_SHARED=${BUILD_SHARED}
        -DWITH_PERF_TOOL=OFF
        -DWITH_DOCS=OFF
        -DWITH_NSS=OFF
        -DZMQ_BUILD_DRAFT_API=ON
        ${FEATURE_OPTIONS}
    OPTIONS_DEBUG
        "-DCMAKE_PDB_OUTPUT_DIRECTORY=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
)

vcpkg_install_cmake()

vcpkg_copy_pdbs()

if(EXISTS ${CURRENT_PACKAGES_DIR}/CMake)
    vcpkg_fixup_cmake_targets(CONFIG_PATH CMake)
endif()
if(EXISTS ${CURRENT_PACKAGES_DIR}/share/cmake/ZeroMQ)
    vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/ZeroMQ)
endif()

file(COPY
    ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake
    DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}
)

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
    vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/include/zmq.h
        "defined ZMQ_STATIC"
        "1 //defined ZMQ_STATIC"
    )
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
    file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
endif()

# Handle copyright
file(RENAME ${CURRENT_PACKAGES_DIR}/share/zmq/COPYING.LESSER.txt ${CURRENT_PACKAGES_DIR}/share/zeromq/copyright)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include ${CURRENT_PACKAGES_DIR}/debug/share ${CURRENT_PACKAGES_DIR}/share/zmq)

# CMake integration test
vcpkg_test_cmake(PACKAGE_NAME ZeroMQ)

and here is the one for cppzmq

include(vcpkg_common_functions)

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO zeromq/cppzmq
    REF v4.4.1
    SHA512 5178a24413e44a6d99e57db7c9859c72279304272baa0e1fb810174cdf592cb567cab98428ef3ab611042bdf4bc506867421662409d1f0d82c233cb83ebdb801
    HEAD_REF master
)

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
    PREFER_NINJA
    OPTIONS 
        -DCPPZMQ_BUILD_TESTS=OFF
        -DZMQ_BUILD_DRAFT_API=ON
)



vcpkg_install_cmake()

vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/cppzmq)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug ${CURRENT_PACKAGES_DIR}/share/cppzmq/libzmq-pkg-config)

# Handle copyright
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/cppzmq)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/cppzmq/LICENSE ${CURRENT_PACKAGES_DIR}/share/cppzmq/copyright)

DUMPBIN output of the exported symbols shows that the relevant symbols are missing

Microsoft (R) COFF/PE Dumper Version 14.16.27032.1
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file E:\_dev\vcpkg\installed\x64-windows\lib\libzmq-mt-4_3_3.lib

File Type: LIBRARY

COFF SYMBOL TABLE
000 01016998 ABS    notype       Static       | @comp.id
001 00000000 SECT2  notype       External     | __IMPORT_DESCRIPTOR_libzmq-mt-4_3_3
002 C0000040 SECT2  notype       Section      | .idata$2
003 00000000 SECT3  notype       Static       | .idata$6
004 C0000040 UNDEF  notype       Section      | .idata$4
005 C0000040 UNDEF  notype       Section      | .idata$5
006 00000000 UNDEF  notype       External     | __NULL_IMPORT_DESCRIPTOR
007 00000000 UNDEF  notype       External     | libzmq-mt-4_3_3_NULL_THUNK_DATA

String Table Size = 0x62 bytes

COFF SYMBOL TABLE
000 01016998 ABS    notype       Static       | @comp.id
001 00000000 SECT2  notype       External     | __NULL_IMPORT_DESCRIPTOR

String Table Size = 0x1D bytes

COFF SYMBOL TABLE
000 01016998 ABS    notype       Static       | @comp.id
001 00000000 SECT2  notype       External     | libzmq-mt-4_3_3_NULL_THUNK_DATA

String Table Size = 0x25 bytes

     Exports

       ordinal    name

                  zmq_atomic_counter_dec
                  zmq_atomic_counter_destroy
                  zmq_atomic_counter_inc
                  zmq_atomic_counter_new
                  zmq_atomic_counter_set
                  zmq_atomic_counter_value
                  zmq_bind
                  zmq_close
                  zmq_connect
                  zmq_ctx_destroy
                  zmq_ctx_get
                  zmq_ctx_new
                  zmq_ctx_set
                  zmq_ctx_shutdown
                  zmq_ctx_term
                  zmq_curve_keypair
                  zmq_curve_public
                  zmq_device
                  zmq_disconnect
                  zmq_errno
                  zmq_getsockopt
                  zmq_has
                  zmq_init
                  zmq_msg_close
                  zmq_msg_copy
                  zmq_msg_data
                  zmq_msg_get
                  zmq_msg_gets
                  zmq_msg_init
                  zmq_msg_init_data
                  zmq_msg_init_size
                  zmq_msg_more
                  zmq_msg_move
                  zmq_msg_recv
                  zmq_msg_send
                  zmq_msg_set
                  zmq_msg_size
                  zmq_poll
                  zmq_proxy
                  zmq_proxy_steerable
                  zmq_recv
                  zmq_recviov
                  zmq_recvmsg
                  zmq_send
                  zmq_send_const
                  zmq_sendiov
                  zmq_sendmsg
                  zmq_setsockopt
                  zmq_sleep
                  zmq_socket
                  zmq_socket_monitor
                  zmq_stopwatch_intermediate
                  zmq_stopwatch_start
                  zmq_stopwatch_stop
                  zmq_strerror
                  zmq_term
                  zmq_threadclose
                  zmq_threadstart
                  zmq_timers_add
                  zmq_timers_cancel
                  zmq_timers_destroy
                  zmq_timers_execute
                  zmq_timers_new
                  zmq_timers_reset
                  zmq_timers_set_interval
                  zmq_timers_timeout
                  zmq_unbind
                  zmq_version
                  zmq_z85_decode
                  zmq_z85_encode

  Summary

          DB .debug$S
          14 .idata$2
          14 .idata$3
           8 .idata$4
           8 .idata$5
          14 .idata$6

How to enable the DRAFT API with vcpkg?


Answer:

Solved with the help from the 0MQ github community: I was using a wrong switch.

It must be -DENABLE_DRAFTS=ON here. ZMQ_BUILD_DRAFT_API is the preprocessor definition, but the CMake option is called ENABLE_DRAFTS.

On top of that, the preprocessor ZMQ_BUILD_DRAFT_API must still be defined in the VS project.

I wish info like this could be easier to look up.

Question:

I want to play around with network programming using ZeroMQ

I'm trying to install it on my Linux Mint 18.2 machine. Maybe I'm just dumb (which is why I come here for help) but I can't seem to get these instructions work.

Mainly following this, from the hyper-linked instructions:

To build on UNIX-like systems

If you have free choice, the most comfortable OS for developing with ZeroMQ is probably Ubuntu.

  1. Make sure that libtool, pkg-config, build-essential, autoconf, and automake are installed.
  2. Check whether uuid-dev package, uuid/e2fsprogs RPM or equivalent on your system is installed.
  3. Unpack the .tar.gz source archive.
  4. Run ./configure, followed by make.
  5. To install ZeroMQ system-wide run sudo make install.
  6. On Linux, run sudo ldconfig after installing ZeroMQ.

Using the tarball from release 4.2.2.

To test, I used the hello world example from 0mq (in examples/c++):

git clone --depth=1 https://github.com/imatix/zguide.git

I tried to compile hwclient.cpp using g++ but I get a bunch of errors, I assume because I cannot find the included zmq.hpp anywhere on my system (used locate zmq.hpp). Here are the errors:

/tmp/ccsb8olx.o: In function `zmq::error_t::error_t()':
hwclient.cpp:(.text._ZN3zmq7error_tC2Ev[_ZN3zmq7error_tC5Ev]+0x26): undefined reference to `zmq_errno'
/tmp/ccsb8olx.o: In function `zmq::error_t::what() const':
hwclient.cpp:(.text._ZNK3zmq7error_t4whatEv[_ZNK3zmq7error_t4whatEv]+0x16): undefined reference to `zmq_strerror'
/tmp/ccsb8olx.o: In function `zmq::message_t::message_t()':
hwclient.cpp:(.text._ZN3zmq9message_tC2Ev[_ZN3zmq9message_tC5Ev]+0x23): undefined reference to `zmq_msg_init'
/tmp/ccsb8olx.o: In function `zmq::message_t::message_t(unsigned long)':
hwclient.cpp:(.text._ZN3zmq9message_tC2Em[_ZN3zmq9message_tC5Em]+0x2e): undefined reference to `zmq_msg_init_size'
/tmp/ccsb8olx.o: In function `zmq::message_t::~message_t()':
hwclient.cpp:(.text._ZN3zmq9message_tD2Ev[_ZN3zmq9message_tD5Ev]+0x14): undefined reference to `zmq_msg_close'
/tmp/ccsb8olx.o: In function `zmq::message_t::data()':
hwclient.cpp:(.text._ZN3zmq9message_t4dataEv[_ZN3zmq9message_t4dataEv]+0x14): undefined reference to `zmq_msg_data'
/tmp/ccsb8olx.o: In function `zmq::context_t::context_t(int)':
hwclient.cpp:(.text._ZN3zmq9context_tC2Ei[_ZN3zmq9context_tC5Ei]+0x18): undefined reference to `zmq_init'
/tmp/ccsb8olx.o: In function `zmq::context_t::~context_t()':
hwclient.cpp:(.text._ZN3zmq9context_tD2Ev[_ZN3zmq9context_tD5Ev]+0x23): undefined reference to `zmq_term'
/tmp/ccsb8olx.o: In function `zmq::socket_t::socket_t(zmq::context_t&, int)':
hwclient.cpp:(.text._ZN3zmq8socket_tC2ERNS_9context_tEi[_ZN3zmq8socket_tC5ERNS_9context_tEi]+0x26): undefined reference to `zmq_socket'
/tmp/ccsb8olx.o: In function `zmq::socket_t::close()':
hwclient.cpp:(.text._ZN3zmq8socket_t5closeEv[_ZN3zmq8socket_t5closeEv]+0x26): undefined reference to `zmq_close'
/tmp/ccsb8olx.o: In function `zmq::socket_t::connect(char const*)':
hwclient.cpp:(.text._ZN3zmq8socket_t7connectEPKc[_ZN3zmq8socket_t7connectEPKc]+0x25): undefined reference to `zmq_connect'
/tmp/ccsb8olx.o: In function `zmq::socket_t::send(zmq::message_t&, int)':
hwclient.cpp:(.text._ZN3zmq8socket_t4sendERNS_9message_tEi[_ZN3zmq8socket_t4sendERNS_9message_tEi]+0x2b): undefined reference to `zmq_send'
hwclient.cpp:(.text._ZN3zmq8socket_t4sendERNS_9message_tEi[_ZN3zmq8socket_t4sendERNS_9message_tEi]+0x46): undefined reference to `zmq_errno'
/tmp/ccsb8olx.o: In function `zmq::socket_t::recv(zmq::message_t*, int)':
hwclient.cpp:(.text._ZN3zmq8socket_t4recvEPNS_9message_tEi[_ZN3zmq8socket_t4recvEPNS_9message_tEi]+0x2b): undefined reference to `zmq_recv'
hwclient.cpp:(.text._ZN3zmq8socket_t4recvEPNS_9message_tEi[_ZN3zmq8socket_t4recvEPNS_9message_tEi]+0x46): undefined reference to `zmq_errno'
collect2: error: ld returned 1 exit status

And for convenience, here is the hwclient.cpp code:

//
//  Hello World client in C++
//  Connects REQ socket to tcp://localhost:5555
//  Sends "Hello" to server, expects "World" back
//
#include <zmq.hpp>
#include <string>
#include <iostream>

int main ()
{
    //  Prepare our context and socket
    zmq::context_t context (1);
    zmq::socket_t socket (context, ZMQ_REQ);

    std::cout << "Connecting to hello world server..." << std::endl;
    socket.connect ("tcp://localhost:5555");

    //  Do 10 requests, waiting each time for a response
    for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
        zmq::message_t request (5);
        memcpy (request.data (), "Hello", 5);
        std::cout << "Sending Hello " << request_nbr << "..." << std::endl;
        socket.send (request);

        //  Get the reply.
        zmq::message_t reply;
        socket.recv (&reply);
        std::cout << "Received World " << request_nbr << std::endl;
    }
    return 0;
}

I'm trying to figure out why zmq.hpp was not being installed.

Can anyone offer any advice on what I might be doing wrong?

Thanks.


Answer:

As discussed over the comments, you need to give the correct linking parameter to g++

g++ hwclient.cpp -lzmq

Explanation: g++ compilation works in phases, the last of which is "linking", where your file is linked with "libraries" containing the pre-compiled "definitions" (of for example, functions that you're calling).

This is in contrast to the "pre-processing" stage that handles including of header files. Header files (most of the time) contain the "declarations" of functions.

Long story short: if you see undefined reference to errors, you're missing some library during linking.