错误:尚未声明'zmq'

error: 'zmq' has not been declared

本文关键字:zmq 未声明 错误      更新时间:2023-10-16

在构建/编译时,我收到以下错误:

C:Ethemain.cpp: In function 'int main()':
C:Ethemain.cpp:11:4: error: 'zmq' has not been declared
C:Ethemain.cpp:11:19: error: expected ';' before 'context'
C:Ethemain.cpp:12:4: error: 'zmq' has not been declared
C:Ethemain.cpp:12:18: error: expected ';' before 'socket'
C:Ethemain.cpp:14:4: error: 'zmq' has not been declared

main.cpp:

#include <zmq.h>
#include <iostream>
#include <string>
int main()
{
   std::string tip;
   std::cout << "Enter Target IP: ";
   std::cin >> tip;
   zmq::context_t context (1);
   zmq::socket_t socket (context, ZMQ_REQ);
   std::cout << "Connecting to " << tip << std::endl;
   zmq::socket.connect ("tcp://"+tip+":5555");
   return 0;
}

有人知道我该怎么解决这个问题吗?

您需要添加#include <zmq.hpp>,这将包括libzmq的C++api。但是,在zmqverions2.x版本中,它包含在安装中,而现在在zmq-3.x.y版本中,不再随库提供它,正如您可以从中看到的那样http://github.com/zeromq/zeromq3-x/raw/master/NEWS

C++api被排除在核心库之外,因为zeromq的"少即是多"策略。它仍然可以从以下位置下载:https://github.com/zeromq/cppzmq/blob/master/zmq.hpp

这个头是围绕C API zeromq的所有C结构和函数编写的,因此整个C++API是一个单独的头文件。可从上面的链接下载。

如果您自己编写zmq.h,它应该是"zmq.h"