gpt4 book ai didi

c++ - VS2013 错误 : LNK2019 When trying to build ZeroMQ server

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:44:06 25 4
gpt4 key购买 nike

我正在尝试在 Visual Studio 2013 上用 C++ 构建这个简单的 ZeroMQ 服务器。

#include "stdafx.h"
#include "zmq.hpp"
#include <string>
#include <iostream>
#include <windows.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
// Prepare context and socket
zmq::context_t ctx(1);
zmq::socket_t sckt(ctx, ZMQ_REP);
sckt.bind("tcp://*:5555");

while (true) {
zmq::message_t request;

// Wait for next request from client
sckt.recv(&request);
std::cout << "Received Hello" << endl;
Sleep(1);

// Send reply back to client
zmq::message_t reply(5);
memcpy((void*)reply.data(), "World", 5);
sckt.send(reply);
}
return EXIT_SUCCESS;
}

但是,当我尝试构建 VS 项目时遇到错误 LNK2019。以下是编译器输出:

1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_errno referenced in function "public: __thiscall zmq::error_t::error_t(void)" (??0error_t@zmq@@QAE@XZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_strerror referenced in function "public: virtual char const * __thiscall zmq::error_t::what(void)const " (?what@error_t@zmq@@UBEPBDXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_ctx_new referenced in function "public: __thiscall zmq::context_t::context_t(int,int)" (??0context_t@zmq@@QAE@HH@Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_ctx_set referenced in function "public: __thiscall zmq::context_t::context_t(int,int)" (??0context_t@zmq@@QAE@HH@Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_ctx_destroy referenced in function "public: void __thiscall zmq::context_t::close(void)" (?close@context_t@zmq@@QAEXXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_init referenced in function "public: __thiscall zmq::message_t::message_t(void)" (??0message_t@zmq@@QAE@XZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_init_size referenced in function "public: __thiscall zmq::message_t::message_t(unsigned int)" (??0message_t@zmq@@QAE@I@Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_send referenced in function "public: bool __thiscall zmq::socket_t::send(class zmq::message_t &,int)" (?send@socket_t@zmq@@QAE_NAAVmessage_t@2@H@Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_recv referenced in function "public: bool __thiscall zmq::socket_t::recv(class zmq::message_t *,int)" (?recv@socket_t@zmq@@QAE_NPAVmessage_t@2@H@Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_close referenced in function "public: __thiscall zmq::message_t::~message_t(void)" (??1message_t@zmq@@QAE@XZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_msg_data referenced in function "public: void * __thiscall zmq::message_t::data(void)" (?data@message_t@zmq@@QAEPAXXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_socket referenced in function "public: __thiscall zmq::socket_t::socket_t(class zmq::context_t &,int)" (??0socket_t@zmq@@QAE@AAVcontext_t@1@H@Z)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_close referenced in function "public: void __thiscall zmq::socket_t::close(void)" (?close@socket_t@zmq@@QAEXXZ)
1>ZeroMQServer.obj : error LNK2019: unresolved external symbol __imp__zmq_bind referenced in function "public: void __thiscall zmq::socket_t::bind(char const *)" (?bind@socket_t@zmq@@QAEXPBD@Z)
1>D:\[ Source Code ]\C++\ZeroMQServer\Debug\ZeroMQServer.exe : fatal error LNK1120: 14 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我已经安装了 ZeroMQ binary v4.0.4并更新了 VS 项目属性以指向 ZeroMQ 的包含和库路径。具体来说,这是我在项目属性中更新的内容(我怀疑其中一些设置可能是多余的):

  1. 配置属性 > VC++ 目录 > 包含目录:已添加 '$(ZEROMQ_HOME)\include'
  2. 配置属性 > VC++ 目录 > 库目录:添加了“$(ZEROMQ_HOME)\lib”
  3. 配置属性 > C/C++ > 常规 > 附加包含目录:已添加 '$(ZEROMQ_HOME)\include'
  4. 配置属性 > 链接器 > 输入 > 附加依赖项:添加了“libzmq-v120-mt-4_0_4.lib;libzmq-v120-mt-gd-4_0_4.lib”

我使用的是 Win 7,64 位版本。请帮我解决这个问题。

最佳答案

根据zeromq.org上的图书馆名称,您正在尝试链接同一个库两次:首先是发布版本,然后是调试版本。

从 Release 配置中删除 libzmq-v120-mt-gd-4_0_4.lib,并从 Debug 配置中删除 libzmq-v120-mt-4_0_4.lib

[编辑]

您的应用程序可能是 32 位的,而您尝试链接的库是 64 位的。 (您可以使用 dumpbin 来确定 .lib 文件的架构,see this answer for an example。请使用 32 位库,或将您的应用程序更改为 64 位。

关于c++ - VS2013 错误 : LNK2019 When trying to build ZeroMQ server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30853698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com