gpt4 book ai didi

c - 如何在c程序中编译expat xml解析?以及在哪里安装 expat。 cygwin编译器中文件放置的位置

转载 作者:行者123 更新时间:2023-11-30 14:37:23 29 4
gpt4 key购买 nike

这是我第一次使用外部 header ,我对外籍人士一无所知。Expat 官方网站对于初学者来说没什么用。我需要使用 expat.h 用 C 语言编译 XML 解析器代码。我已经下载了 expat 文件并将路径包含在头文件中。但在编译时出现错误。在windows平台上 enter image description here

enter image description here

    #include "C:\Program Files (x86)\Expat 2.2.7\Source\lib\expat.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int parse_xml(char *buff)
{
FILE *fp;
fp = fopen("config.xml", "r");
if(fp == NULL)
{
printf("Failed to open file\n");
return 1;
}

/* Obtain the file size. */
fseek (fp, 0, SEEK_END);
size_t file_size = ftell(fp);
rewind(fp);

XML_Parser parser = XML_ParserCreate(NULL);
int done;
memset(buff, 0, sizeof(buff));

do
{
size_t len = fread(buff, 1, file_size, fp);
done = len < sizeof(buff);

if(XML_Parse(parser, buff, len, done) == XML_STATUS_ERROR)
{
printf("%s at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentLineNumber(parser));
return 1;
}
}
while(!done);

fclose(fp);
XML_ParserFree(parser);

return 0;
}

这是代码,路径是安装后expat.h所在的位置。

xml代码

`<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>`

请帮忙!

最佳答案

您似乎知道必须执行 -lexpat 以便头文件实际上链接到某些内容,但您忘记将 Expat 添加到链接路径。添加此命令行选项:-L/path/to/your/expat/lib/directory。对于 WinMain 错误,请尝试添加 -Wl,-subsystem,console。希望对您有帮助!

关于c - 如何在c程序中编译expat xml解析?以及在哪里安装 expat。 cygwin编译器中文件放置的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57375894/

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