2

ここの公式ZeroMQサイトで提供されている基本的な例があります(「Ask and Ye Shall Receive」セクションまでスクロールします):

// Hello World server

#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>

int main (void)
{
    // Socket to talk to clients
    void *context = zmq_ctx_new (); // LINE NUMBER 9
    void *responder = zmq_socket (context, ZMQ_REP);
    int rc = zmq_bind (responder, "tcp://*:5555");
    assert (rc == 0);

    while (1) {
        char buffer [10];
        zmq_recv (responder, buffer, 10, 0); // LINE NUMBER 15
        printf ("Received Hello\n");
        zmq_send (responder, "World", 5, 0); // LINE NUMBER 17
        sleep (1); // Do some 'work'
    }
    return 0;
}

Ubuntu 12.04 LTS を使用しており、標準リポジトリから ZeroMQ をインストールしました。しかし、上記の例をコンパイルしようとすると、次のエラーが発生します。

./test.c: In function ‘main’:
./test.c:9:21: warning: initialization makes pointer from integer without a cast [enabled by default]
./test.c:15:9: warning: passing argument 2 of ‘zmq_recv’ from incompatible pointer type [enabled by default]
/usr/include/zmq.h:228:16: note: expected ‘struct zmq_msg_t *’ but argument is of type ‘char *’
./test.c:15:9: error: too many arguments to function ‘zmq_recv’
/usr/include/zmq.h:228:16: note: declared here
./test.c:17:9: warning: passing argument 2 of ‘zmq_send’ from incompatible pointer type [enabled by default]
/usr/include/zmq.h:227:16: note: expected ‘struct zmq_msg_t *’ but argument is of type ‘char *’
./test.c:17:9: error: too many arguments to function ‘zmq_send’
/usr/include/zmq.h:227:16: note: declared here

zmq_recvそこで、 and zmq_sendinの定義を調べた/usr/include/zmq.hところ、コンパイラが実際に真実を語っていることがわかりました。署名は次のとおりです。

int zmq_bind (void *s, const char *addr);
int zmq_send (void *s, zmq_msg_t *msg, int flags);
int zmq_recv (void *s, zmq_msg_t *msg, int flags);

では、このサイトのドキュメントが間違っている (または古い可能性がある) と考えるのは正しいでしょうか? 他の誰かがこの問題を経験しましたか?

4

1 に答える 1

3

これは機能します。開発パッケージがないため、この問題が発生しています。ubuntuで確認しました。

#sudo apt-get install libzmq3-dev
#gcc  test.c -o Zmserver.out -lzmq
于 2015-08-27T04:11:57.890 に答える