gpt4 book ai didi

c - ZEROMQ 编译器错误中的 zhelpers.h

转载 作者:行者123 更新时间:2023-11-30 15:32:01 37 4
gpt4 key购买 nike

我最近开始学习 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 专家,但这个软件看起来像是我跨越论文障碍的现实希望。

谢谢。

最佳答案

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

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

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

关于c - ZEROMQ 编译器错误中的 zhelpers.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24469077/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com