gcc – ZeroMQ错误:未知类型名称’zctx_t’

我尝试按照此链接中的教程:
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 ..

最佳答案 此代码使用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找到所有样品的现代化版本.

点赞