【问题标题】:error: 'zmq' has not been declared错误:“zmq”尚未声明
【发布时间】:2013-08-21 18:50:04
【问题描述】:

在构建/编译时出现此错误:

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 &lt;zmq.h&gt;
  • @DennisMeng 我试过了,没什么区别
  • 那么,那个头文件到底在哪里?
  • @DennisMeng 它在我的程序文件中,安装了 zmq 的源代码及其包含的库。
  • 您确定socket_tcontext_t 是在zmq.h 中定义的吗?

标签: c++ build compilation declaration zeromq


【解决方案1】:

您需要添加#include &lt;zmq.hpp&gt; 这将包括libzmq 的C++ api。但是,在 zmq 版本 2.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 结构和函数 C API zeromq 编写的,因此整个 C++ API 是一个单独的头文件。可从上面的链接下载。

【讨论】:

    【解决方案2】:

    如果是你自己写的zmq.h,应该是"zmq.h"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多