使用libXml2在c++与Netbeans



我有一个问题,使c++代码在Netbeans中正确编译,特别是处理libXml2的代码。我下载了libXml2,把它放在包含文件夹中,我知道代码本身没有任何libXml2引用编译得很好,但是,当我添加以下函数时:

void XmlParser::processNode(xmlTextReaderPtr reader){
    const xmlChar *name, *value;
    name = xmlTextReaderConstName(reader);
    if (name == NULL)
    name = BAD_CAST "--";
    value = xmlTextReaderConstValue(reader);
    printf("%d %d %s %d %d",
        xmlTextReaderDepth(reader),
        xmlTextReaderNodeType(reader),
        name,
        xmlTextReaderIsEmptyElement(reader),
        xmlTextReaderHasValue(reader));
    if (value == NULL)
    printf("n");
    else {
        if (xmlStrlen(value) > 40)
            printf(" %.40s...n", value);
        else
        printf(" %sn", value);
    }
}
void XmlParser::streamFile(const char *filename) {
    xmlTextReaderPtr reader;
    int ret;
    reader = xmlReaderForFile(filename, NULL, 0);
    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
        while (ret == 1) {
            //processNode(reader);
            ret = xmlTextReaderRead(reader);
        }
        xmlFreeTextReader(reader);
        if (ret != 0) {
            fprintf(stderr, "%s : failed to parsen", filename);
        }
    } else {
        fprintf(stderr, "Unable to open %sn", filename);
    }
}
当我单击build时,我得到以下结果:

构建/调试/MinGW-Windows/xmlparse。0:在函数ZN9XmlParser11processNodeEP14_xmlTextReader': C:Users...DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:26: undefined reference to xmlTextReaderConstName'C:Users…DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:30:未定义的引用xmlTextReaderConstValue' C:Users...DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:37: undefined reference to xmlTextReaderHasValue'C:Users…DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:37:未定义的引用xmlTextReaderIsEmptyElement' C:Users...DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:37: undefined reference to xmlTextReaderNodeType'C:Users…DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:37:未定义的引用xmlTextReaderDepth' C:Users...DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:41: undefined reference to xmlStrlen'构建/调试/MinGW-Windows/xmlparse。0:在函数ZN9XmlParser10streamFileEPKc': C:Users...DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:51: undefined reference to xmlReaderForFile中C:Users…DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:53:未定义的引用xmlTextReaderRead' C:Users...DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:56: undefined reference to xmlTextReaderRead'C:Users…DocumentsNetBeansProjectsXmlBallotParser/XmlParser.cpp:58:未定义引用' xmlFreeTextReader'

这表明我有某种问题编译程序使用libXml2。我看到有人在这里有同样的错误,并且这个问题的答案是正确地设置了编译程序的参数,但是,我无法弄清楚如何在NetBeans/Windows中做到这一点。我想我需要的是如何得到正确论证的细节。任何帮助都会很感激。谢谢你。

添加-lxml2 (gcc)或libxml2.lib (visual studio)到您的链接器

相关内容

  • 没有找到相关文章