2

我正在为我的应用程序使用 zeromq api,并且有以下指示的链接问题。我已经在我的 ubuntu 12.10 系统中安装了 zeromq 和 czmq tar 球,并验证了 /usr/local/include 下是否存在必要的头文件(例如 zmq.h)。你能告诉我为什么我会遇到这些链接问题吗?什么是可能的解决方案。我还安装了 zmq c++ 绑定(zmq.hpp)。

/XXXX.cpp:92: undefined reference to `zmq_poll'
CMakeFiles/dummy.dir/__/xxx_api/TheQueue.cpp.o: In function`zmq::error_t::error_t()':

/usr/local/include/zmq.hpp:76: undefined reference to `zmq_errno'
CMakeFiles/dummy.dir/__/xxx_api/TheQueue.cpp.o: In function `zmq::error_t::what() const':

 /usr/local/include/zmq.hpp:80: undefined reference to `zmq_strerror'
 CMakeFiles/dummy.dir/__/xxx/TheQueue.cpp.o: In function`zmq::context_t::context_t(int)':

/usr/local/include/zmq.hpp:241: undefined reference to `zmq_init'
CMakeFiles/dummy.dir/__/control_api/TheQueue.cpp.o: In function `zmq::context_t::close()':

/usr/local/include/zmq.hpp:267: undefined reference to `zmq_term'
CMakeFiles/dummy.dir/__/xxx_api/TheQueue.cpp.o: In function `zmq::socket_t::socket_t(zmq::context_t&, int)':

collect2: error: ld returned 1 exit status
make[2]: *** [/xxx/build_output/dummy] Error 1
make[1]: *** [/xxx/CMakeFiles/dummy.dir/all] Error 2
4

1 回答 1

5

以下示例适用于我:

在这里,我有我的文件,其中包含以下内容:

#include "cppzmq/zmq.hpp"
#include <string>
#include <iostream>

int main ()
{
    //  Prepare our context and socket
    zmq::context_t context (1);
    zmq::socket_t socket (context, ZMQ_REQ);

    std::cout << "Connecting to hello world server…" << std::endl;
    socket.connect ("tcp://localhost:5555");

    //  Do 10 requests, waiting each time for a response
    for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
        zmq::message_t request (6);
        memcpy ((void *) request.data (), "Hello", 5);
        std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
        socket.send (request);

        //  Get the reply.
        zmq::message_t reply;
        socket.recv (&reply);
        std::cout << "Received World " << request_nbr << std::endl;
    }
    return 0;
}

然后在这里我有以下命令,它编译它:

g++ test.cpp -o test -lzmq

为了让 zmq 在我的 linux 机器上工作,我只是从他们的网站下载了 zeromq 作为 tarball(适用于 unix/linux)。然后我跑了

make && make install
于 2014-01-12T12:31:43.020 回答