2014-06-28 67 views
0

我最近開始學習ZEROMQ,我被困在某個地方。我試圖運行天氣更新示例(wuclient.c和wuserver.c),我得到下面的錯誤。ZEROMQ中的zhelpers.h編譯器錯誤

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的專家,但是這個軟件看起來像是我縮小論文障礙的現實希望。

謝謝。

回答

1

請注意,這些只是警告而不是錯誤。編譯器仍然會生成一些內容,但它可能無法按預期工作。

在Ubuntu上,頭文件「zhelpers.h」包括<sys/time.h>而不是<time.h>。這很可能是不正確的。刪除「zhelpers.h」中的條件,並在所有平臺上包含<time.h>。這將刪除一半的警告。

警告的後半部分與「zhelpers.h」中有函數定義有關。這是非常糟糕的編碼風格,但程序應該仍然有效。

+0

你說得對。這些函數定義可能更具有「靜態內聯」功能。 –