错误:'zmq'尚未声明

时间:2013-08-19 20:50:25

标签: c++ build compilation declaration zeromq

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

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;
}

任何人对我如何解决这个问题有任何想法?

2 个答案:

答案 0 :(得分:6)

你需要添加#include <zmq.hpp>这将包括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是单个标头文件。可从上面的链接下载。

答案 1 :(得分:0)

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

相关问题