【问题标题】:zhelpers.h in ZEROMQ compiler errorZEROMQ 编译器错误中的 zhelpers.h
【发布时间】:2014-06-28 16:59:43
【问题描述】:

我最近开始学习 ZEROMQ,但我被困在某个地方。我尝试运行天气更新示例(wuclient.c 和 wuserver.c),但出现以下错误。

In file included from wuclient.c:5:0:
zhelpers.h: In function ‘s_sleep’:
zhelpers.h:133:5: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
zhelpers.h: In function ‘s_console’:
zhelpers.h:158:5: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
zhelpers.h:159:12: warning: implicit declaration of function ‘localtime’ [-Wimplicit-function-declaration]
zhelpers.h:159:26: warning: initialization makes pointer from integer without a cast [enabled by default]
zhelpers.h:161:5: warning: implicit declaration of function ‘strftime’ [-Wimplicit-function-declaration]
zhelpers.h:161:5: warning: incompatible implicit declaration of built-in function ‘strftime’ [enabled by default]
wuclient.c: At top level:
zhelpers.h:60:1: warning: ‘s_send’ defined but not used [-Wunused-function]
zhelpers.h:67:1: warning: ‘s_sendmore’ defined but not used [-Wunused-function]
zhelpers.h:75:1: warning: ‘s_dump’ defined but not used [-Wunused-function]
zhelpers.h:115:1: warning: ‘s_set_id’ defined but not used [-Wunused-function]
zhelpers.h:125:1: warning: ‘s_sleep’ defined but not used [-Wunused-function]
zhelpers.h:139:1: warning: ‘s_clock’ defined but not used [-Wunused-function]
zhelpers.h:156:1: warning: ‘s_console’ defined but not used [-Wunused-function]

我用来编译的命令是:gcc -Wall wuclient.c -o wuclient -L/usr/local/lib -lzmq

这是导致错误的 zhelpers.h 代码https://github.com/imatix/zguide/blob/master/examples/C/zhelpers.h

它包含在下面的代码中:

//  Weather update client
//  Connects SUB socket to tcp://localhost:5556
//  Collects weather updates and finds avg temp in zipcode

#include "zhelpers.h"

int main (int argc, char *argv [])
{
    //  Socket to talk to server
    printf ("Collecting updates from weather server...\n");
    void *context = zmq_ctx_new ();
    void *subscriber = zmq_socket (context, ZMQ_SUB);
    int rc = zmq_connect (subscriber, "tcp://localhost:5556");
    assert (rc == 0);

    //  Subscribe to zipcode, default is NYC, 10001
    char *filter = (argc > 1)? argv [1]: "10001 ";
    rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
                         filter, strlen (filter));
    assert (rc == 0);

    //  Process 100 updates
    int update_nbr;
    long total_temp = 0;
    for (update_nbr = 0; update_nbr < 100; update_nbr++) {
        char *string = s_recv (subscriber);

        int zipcode, temperature, relhumidity;
        sscanf (string, "%d %d %d",
            &zipcode, &temperature, &relhumidity);
        total_temp += temperature;
        free (string);
    }
    printf ("Average temperature for zipcode '%s' was %dF\n",
        filter, (int) (total_temp / update_nbr));

    zmq_close (subscriber);
    zmq_ctx_destroy (context);
    return 0;
}

我打开了“zhelpers.h”文件,其中包含了“time.h”。所以我很困惑为什么会发生这种情况。我正在使用 Ubuntu 12.04,请,我既不是 C 或 ZEROMQ 方面的专家,但这个软件看起来像是我扩大论文障碍的现实希望。

谢谢。

【问题讨论】:

    标签: c function gcc


    【解决方案1】:

    请注意,这些只是警告而不是错误。编译器仍会生成一些内容,但可能无法按预期工作。

    头文件“zhelpers.h”包括 而不是 Ubuntu 上的 。这很可能是不正确的。删除“zhelpers.h”中的条件,只在所有平台上包含 。这将删除一半的警告。

    后半部分的警告与“zhelpers.h”中有函数定义有关。这是非常糟糕的编码风格,但程序应该仍然可以工作。

    【讨论】:

    • 你是对的。这些函数定义作为static inline 函数可能更有意义。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多