错误:未声明“zmq”

3

构建/编译时我遇到了这个错误:

C:\Ethe\main.cpp: In function 'int main()':
C:\Ethe\main.cpp:11:4: error: 'zmq' has not been declared
C:\Ethe\main.cpp:11:19: error: expected ';' before 'context'
C:\Ethe\main.cpp:12:4: error: 'zmq' has not been declared
C:\Ethe\main.cpp:12:18: error: expected ';' before 'socket'
C:\Ethe\main.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.h" 而不是 #include <zmq.h> - Dennis Meng
@DennisMeng 这个在我的程序文件中,随着zmq源代码和其包含的库一起安装了。 - Richieaaron Morris
你确定 socket_tcontext_tzmq.h 中被定义了吗? - olevegard
在这种情况下,无论那个地方的位置可能都是问题所在。当您执行#include时,编译器和链接器不会自动查找每个可能的文件夹;它们只会在特定的位置进行查找。 - Dennis Meng
@olevegard 这是我正在使用的示例 http://zguide.zeromq.org/cpp:hwclient - Richieaaron Morris
显示剩余4条评论
2个回答

8
您需要添加#include <zmq.hpp>,这将包含libzmq的C++ api。然而,在zmq 2.x版本中,它已经随安装一起包括了,而现在在zmq-3.x.y版本中,它不再随库一起提供,正如您可以从http://github.com/zeromq/zeromq3-x/raw/master/NEWS中看到的那样。
自zeromq采用了“少即是多”的策略后,该C++ api已被从核心库中删除。但仍可从https://github.com/zeromq/cppzmq/blob/master/zmq.hpp下载。
此头文件围绕所有C结构和函数编写了C API zeromq,因此整个C++ API都是一个单独的头文件,可从上面的链接下载。

0
如果您自己编写了zmq.h文件,则应为"zmq.h"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接