Errors when compiling ZeroMQ's server example

Viewed 405

I created a Visual Studio 2019 project on Windows in which I'm trying to get ZeroMQ's server example to work.

I've downloaded the latest libzmq version from here, extracted that to my VS project directory. I've also downloaded this file and put it inside libzmq's include directory. Then I've added that include directory to the Include Directories in the project's properties.

When trying to compile, I get this output:

1>------ Build started: Project: SimConnect Server, Configuration: Debug x64 ------
1>SimConnect Server.cpp
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_errno referenced in function "public: __cdecl zmq::error_t::error_t(void)" (??0error_t@zmq@@QEAA@XZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_strerror referenced in function "public: virtual char const * __cdecl zmq::error_t::what(void)const " (?what@error_t@zmq@@UEBAPEBDXZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_ctx_new referenced in function "public: __cdecl zmq::context_t::context_t(int,int)" (??0context_t@zmq@@QEAA@HH@Z)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_ctx_set referenced in function "public: __cdecl zmq::context_t::context_t(int,int)" (??0context_t@zmq@@QEAA@HH@Z)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_ctx_destroy referenced in function "public: void __cdecl zmq::context_t::close(void)" (?close@context_t@zmq@@QEAAXXZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_init referenced in function "public: __cdecl zmq::message_t::message_t(void)" (??0message_t@zmq@@QEAA@XZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_init_size referenced in function "public: __cdecl zmq::message_t::message_t<class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > > >(class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >,class std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >)" (??$?0V?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@@message_t@zmq@@QEAA@V?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@0@Z)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_send referenced in function "public: class zmq::detail::trivial_optional<unsigned __int64> __cdecl zmq::detail::socket_base::send(class zmq::message_t &,enum zmq::send_flags)" (?send@socket_base@detail@zmq@@QEAA?AV?$trivial_optional@_K@23@AEAVmessage_t@3@W4send_flags@3@@Z)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_recv referenced in function "public: class zmq::detail::trivial_optional<unsigned __int64> __cdecl zmq::detail::socket_base::recv(class zmq::message_t &,enum zmq::recv_flags)" (?recv@socket_base@detail@zmq@@QEAA?AV?$trivial_optional@_K@23@AEAVmessage_t@3@W4recv_flags@3@@Z)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_close referenced in function "public: __cdecl zmq::message_t::~message_t(void)" (??1message_t@zmq@@QEAA@XZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_data referenced in function "public: void * __cdecl zmq::message_t::data(void)" (?data@message_t@zmq@@QEAAPEAXXZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_msg_size referenced in function "public: unsigned __int64 __cdecl zmq::message_t::size(void)const " (?size@message_t@zmq@@QEBA_KXZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_socket referenced in function "public: __cdecl zmq::socket_t::socket_t(class zmq::context_t &,int)" (??0socket_t@zmq@@QEAA@AEAVcontext_t@1@H@Z)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_close referenced in function "public: void __cdecl zmq::socket_t::close(void)" (?close@socket_t@zmq@@QEAAXXZ)
1>SimConnect Server.obj : error LNK2019: unresolved external symbol __imp_zmq_bind referenced in function "public: void __cdecl zmq::detail::socket_base::bind(char const *)" (?bind@socket_base@detail@zmq@@QEAAXPEBD@Z)
1>C:\Path\To\VS\Project\x64\Debug\SimConnect Server.exe : fatal error LNK1120: 15 unresolved externals
1>Done building project "SimConnect Server.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is the code:

#include <string>
#include <chrono>
#include <thread>
#include <iostream>

#include <zmq.hpp>

int main()
{
    using namespace std::chrono_literals;

    // initialize the zmq context with a single IO thread
    zmq::context_t context{ 1 };

    // construct a REP (reply) socket and bind to interface
    zmq::socket_t socket{ context, ZMQ_REP };
    socket.bind("tcp://127.0.0.1:5555");

    // prepare some static data for responses
    const std::string data{ "World" };

    for (;;)
    {
        zmq::message_t request;

        // receive a request from client
        socket.recv(request, zmq::recv_flags::none);
        std::cout << "Received " << request.to_string() << std::endl;

        // simulate work
        std::this_thread::sleep_for(1s);

        // construct a reply message
        zmq::message_t reply{ data.cbegin(), data.cend() };

        // send the reply to the client
        socket.send(reply, zmq::send_flags::none);
    }

    return 0;
}

From what I've read online, I think I need to install some kind of library for windows, but I've got no idea where to get it from or how to install it.

Please also keep in mind that I'm very new to C++.

0 Answers
Related