gpt4 book ai didi

c++ - 链接 zmq c++ header 时出错

转载 作者:行者123 更新时间:2023-11-28 07:31:48 24 4
gpt4 key购买 nike

我正在尝试在 C++ 项目中使用 zmq。当我想构建一个简单的示例时,我很困惑。

为此,我使用 VisualC++ 2010 的 .sln 单独构建了 libzmq v3.2.3。然后我下载了 zmq.hpp 并将其包含在内。该示例是 zmq 指南的第一个:

//
// Hello World server in C++
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <unistd.h>

int main () {
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REP);
socket.bind ("tcp://*:5555");

while (true) {
zmq::message_t request;

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

// Do some 'work'
sleep (1);

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

编译没问题,但链接不行:我得到这样的错误:

error LNK2019: external symbol unresolved __imp__zmq_term refrenced in function "public: void __thiscall zmq::context_t::close(void)" (?close@context_t@zmq@@QAEXXZ)

zmq 的路径似乎没问题;就是不明白为什么VC++找不到zmq.hpp里面的小方法代码

你看到我忘了做什么吗?

编辑:下面是输出窗口的内容(不好意思,是法文版,不过我觉得挺像的):

1>------ Début de la génération : Projet : libzmq, Configuration : Debug Win32 ------
1> 1 fichier(s) copié(s).
1> libzmq.vcxproj -> <...>\..\Ouptut\Debug\libzmq_d.lib
2>------ Début de la génération : Projet : HelloServeur, Configuration : Debug Win32 ------
2> HelloServeur.cpp
2>HelloServeur.obj : error LNK2019: symbole externe non résolu __imp__zmq_init référencé dans la fonction "public: __thiscall zmq::context_t::context_t(int)" (??0context_t@zmq@@QAE@H@Z)
2>HelloServeur.obj : error LNK2019: symbole externe non résolu __imp__zmq_errno référencé dans la fonction "public: __thiscall zmq::error_t::error_t(void)" (??0error_t@zmq@@QAE@XZ)
2>HelloServeur.obj : error LNK2019: symbole externe non résolu __imp__zmq_strerror référencé dans la fonction "public: virtual char const * __thiscall zmq::error_t::what(void)const " (?what@error_t@zmq@@UBEPBDXZ)
2>HelloServeur.obj : error LNK2019: symbole externe non résolu __imp__zmq_term référencé dans la fonction "public: void __thiscall zmq::context_t::close(void)" (?close@context_t@zmq@@QAEXXZ)
2><...>\..\Ouptut\Debug\HelloServeur.exe : fatal error LNK1120: 4 externes non résolus
========== Génération : 1 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========

最佳答案

如果您使用的是静态库,则需要将 .lib 添加到链接器设置中,在链接器 | 下输入|项目设置中的其他依赖项。

关于c++ - 链接 zmq c++ header 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17524435/

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