2012-10-11 82 views
0

我想在我的Win 7機器上使用cygwin上的libxml2編寫一個xml解析器。 當我試圖編譯代碼時,它給我編譯時錯誤。有人能幫我解決這個問題嗎?使用libxml2的C代碼給Win 7上的cygwin編譯時錯誤

[email protected] /cygdrive/c/Users/ad/Desktop 
$ gcc xmlparser.c -I /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/ -L /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/lib/libxml2.lib -o pxml 
In file included from /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/parser.h:807, 
      from xmlparser.c:8: 
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:28:19: iconv.h: No such file or directory 
In file included from /cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/parser.h:807, 
      from xmlparser.c:8: 
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:146: error: parse error before "iconv_t" 
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:146: warning: no semicolon at end of struct or union 
/cygdrive/c/Users/ad/Desktop/libxml2-2.7.8.win32/include/libxml/encoding.h:147: warning: data definition has no type or storage class 
xmlparser.c: In function `main': 
xmlparser.c:21: error: `filename' undeclared (first use in this function) 
xmlparser.c:21: error: (Each undeclared identifier is reported only once 
xmlparser.c:21: error: for each function it appears in.) 
xmlparser.c:29: error: parse error before ')' token 
xmlparser.c: At top level: 
xmlparser.c:34: error: parse error before string constant 
xmlparser.c:34: error: conflicting types for 'printf' 
xmlparser.c:34: note: a parameter list with an ellipsis can't match an empty parameter name list declaration 
xmlparser.c:34: error: conflicting types for 'printf' 
xmlparser.c:34: note: a parameter list with an ellipsis can't match an empty parameter name list declaration 
xmlparser.c:34: warning: data definition has no type or storage class 

代碼::

# include <stdio.h> 
# include <stdlib.h> 
# include <libxml/parser.h> 

int main(int argc, char **argv) 
{ 
    xmlDoc *document; 
    xmlNode *root , *node , *first_child; 

    if(argc < 2) 
    { 
     printf("\n Error No filename specified \n"); 
     return 1; 
    } 

    filename = argv[1]; 

    document = xmlReadFile(filename,NULL,0); 
    root = xmlDocGetRootElement(document); 

    printf("\n Root is ::%s:: <%i> \n",root->name,root->type); 
    first_child = root->children; 

    for(node = first_child;node,node = node->next) 
    { 
     printf("\n Child is ::%s:: <%i> \n",node -> name, node->type); 
    } 

    printf("\n END \n"); 
    return 0; 
    } 
+0

我們確實需要代碼來嘗試和幫助.​​..但是從錯誤...聲明'filename' – Mike

+0

您是否嘗試在Linux上構建它? – amn

+0

我嚴重懷疑庫聲明瞭一個名爲'main'的函數,所以問題出在你的代碼中,你沒有顯示,而不是在庫中。向我們展示代碼。 –

回答

1

該錯誤消息說,它明確地說filename沒有宣佈,但你要在這裏使用它:

filename = argv[1]; 

還有一個錯點標點符號:

for(node = first_child;node,node = node->next) 

它必須是;而不是,

+0

..你指出的兩個是我讓我糾正他們的愚蠢錯誤。但是我擔心我從libxml2頭文件中得到的錯誤出現在頂端。你可以看看這個,以及可能是什麼原因 – abhi

+0

顯然,從那些相同的錯誤中可以看出,編譯器無法找到頭文件'iconv.h'。你要麼沒有它,要麼你沒有指定找到它的路徑。 –

+0

我已經在gcc中包含了文件夾路徑並檢查了頭文件iconv.h,但它不在那裏。我有下載其他庫也使用libxml2除了常規的窗口之外的Windows? – abhi