我正在尝试在我的 Win 7 机器上使用 cygwin 上的 libxml2 在 C 中编写一个 xml 解析器。当我试图编译代码时,它会给我编译时错误。有人可以帮我解决这个问题。
ad@ad-PC /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;
}