gpt4 book ai didi

使用 libxml2 的 C 代码在 Win 7 上的 cygwin 上给出编译时错误

转载 作者:行者123 更新时间:2023-11-30 15:54:38 24 4
gpt4 key购买 nike

我正在尝试在我的 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;
}

最佳答案

错误消息明确指出 filename 未声明,但您却试图在此处使用它:

filename = argv[1];

这里还有一个错误的标点符号:

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

它必须是;而不是,

关于使用 libxml2 的 C 代码在 Win 7 上的 cygwin 上给出编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12839230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com