我最近开始学习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代码。
它包含在下面的代码中:
// 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/