[SOLVED]libxml/xmlexports.h : No such file or directory



  • Hello, recently I am following the example for libxml from their official site. The strange error that qtcreator reports is :
    @#ifndef XML_VERSION_H
    #define XML_VERSION_H

    #include <libxml/xmlexports.h>

    #ifdef __cplusplus
    extern "C" {
    #endif

    /*

    • use those to be sure nothing nasty will happen if
    • your library and includes mismatch
      /
      #ifndef LIBXML2_COMPILING_MSCCDEF
      XMLPUBFUN void XMLCALL xmlCheckVersion(int version); // ERROR HERE
      #endif /
      LIBXML2_COMPILING_MSCCDEF */
      @
      But I am sure the header is present in usr/include, Ive less-ed it and double checked for it, also intellisense or autocomplete (not sure how you call it) show all libxml funcions. Ive read this topic :
      https://stackoverflow.com/questions/5636144/error-libxml-parser-h-no-such-file-or-directory/5981599#5981599 but here this does not fix the issue. Here are my includes, or more like the whole example I am following:
      @#include <libxml2/libxml/tree.h>
      #include <libxml2/libxml/parser.h>
      #include <libxml2/libxml/xmlversion.h>
      #include <libxml2/libxml/xmlexports.h>

    #include <stdio.h>

    static const char* document = "<quiz />";

    static void exampleXMLParse(const char*, int);

    int main(void) {
    LIBXML_TEST_VERSION
    exampleXMLParse(document, 6);
    xmlCleanupParser();
    return(0);
    }

    static void exampleXMLParse(const char *content, int length) {
    xmlDocPtr doc;
    doc = xmlReadMemory(content, length, "TestXML.xml", NULL, 0);
    if ( ! doc ) {
    fprintf(stderr, "ERROR READING %s \n", "TestXML");
    return;
    }
    xmlFreeDoc(doc);
    }
    @
    Any info ?


  • Lifetime Qt Champion

    Hi,

    Did you add:

    @INCLUDE += /usr/include/libxml2@

    to your pro file ?



  • Hello, thanks, just did but I got the following errno:
    (assuming the above code)
    @
    undefined reference to 'xmlCheckVersion'
    undefined reference to 'xmlReadMemory'
    undefined reference to 'xmlFreeDoc'
    undefined reference to 'xmlCleanupParser'
    @

    Here is my pro. file:
    @
    #-------------------------------------------------

    Project created by QtCreator 2014-07-05T12:46:42

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = DirectoryDeleter
    TEMPLATE = app
    INCLUDEPATH += /usr/include/libxml2

    SOURCES += main.cpp
    DirectoryDeleter.cpp
    Worker.cpp
    Daemon.cpp
    xmltest.cpp #added for testing

    HEADERS +=
    DirectoryDeleter.h
    Worker.h
    Daemon.h

    @

    Ive cleaned the project, ran qMake form qtcreator, build it again then tried to run... this is the issue. [EDIT] Ive searched for INCLUDE tag but the qtcreator offered INCLUDEPATH and include() ... I guess INCLUDEPATH replaces INCLUDE so I think I`ve did it rigth.


  • Lifetime Qt Champion

    You are not linking to libxml2

    You need to add

    @LIBS += -lxml2@

    To your pro file



  • Thank you so much. I had no idea this is manually done. In gcc I was adding the -lxml2 and it was OK, but no idea the pro. needed it. Thank you again - you were a lifesaver :)


  • Lifetime Qt Champion

    Qt can't guess your external dependencies ;)

    You're welcome !

    Since it's all working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.