ZeroMQ错误:未知类型名称'zctx_t'

时间:2017-02-18 05:46:52

标签: gcc g++ ubuntu-14.04 zeromq

我尝试按照此链接中的教程:http://hintjens.com/blog:49安装ZeroMQ并运行一个简单示例,如下所示:

#include <czmq.h>

int main (void) {
    zctx_t *ctx = zctx_new ();
    void *publisher = zsocket_new (ctx, ZMQ_PUB);
    zsocket_set_curve_server (publisher, true);
    puts ("Hello, Curve!");
    zctx_destroy (&ctx);
    return 0;
}

但是,我收到此错误消息:

hello.c: In function ‘main’:
hello.c:4:5: error: unknown type name ‘zctx_t’
     zctx_t *ctx = zctx_new ();
     ^
hello.c:4:19: warning: initialization makes pointer from integer without a cast [enabled by default]
     zctx_t *ctx = zctx_new ();
                   ^
hello.c:5:23: warning: initialization makes pointer from integer without a cast [enabled by default]
     void *publisher = zsocket_new (ctx, ZMQ_PUB);
                       ^
你能帮帮我吗? 我正在使用Ubuntu 14,并且使用这些命令成功安装了ZeroMQ:

git clone git://github.com/jedisct1/libsodium.git
cd libsodium
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..

git clone git://github.com/zeromq/libzmq.git
cd libzmq
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..

git clone git://github.com/zeromq/czmq.git
cd czmq
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd ..

1 个答案:

答案 0 :(得分:1)

此代码使用CZMQ API v2,该版本已在v3中弃用,在v4中已移除(https://github.com/zeromq/czmq/releases/tag/v4.0.0)。使用v4的等效代码是:

#include <czmq.h>

int main (void) {
    zsock_t *publisher = zsock_new (ZMQ_PUB);
    zsock_set_curve_server (publisher, true);
    puts ("Hello, Curve!");
    zsock_destroy (&publisher);
    return 0;
}

您可以在https://github.com/zeromq/czmq/tree/master/examples/security找到所有样本的现代化版本。