我想在我的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;
}
我們確實需要代碼來嘗試和幫助...但是從錯誤...聲明'filename' – Mike
您是否嘗試在Linux上構建它? – amn
我嚴重懷疑庫聲明瞭一個名爲'main'的函數,所以問題出在你的代碼中,你沒有顯示,而不是在庫中。向我們展示代碼。 –