2

Possible Duplicate:
Adding external library into Qt Creator project

This is my QT Project. I added the external libraries. When i run this program, the following errors are coming:-:-"1: error: cannot find -libxml2" and when i remove "LIBS += -L/usr/local/lib -libxml2" line, it shows "undefined reference to 'xmlstrcmp' and many more errors as same this one. Thanks in advance.

"Test.pro" File (Project File):-

QT       += core gui xml
TARGET = test
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

INCLUDEPATH = /usr/local/include/libxml2

LIBS += -L/usr/local/lib -libxml2

***"MainWindow.h" File(Header File):-***

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlstring.h>
#include <libxml/list.h>
#include <libxml/tree.h>
#include <libxml/SAX.h>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void parseDocument(char *docName);
    void parse(xmlDocPtr doc, xmlNodePtr cur);

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

"MainWindow.cpp"(Class File) :-

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    char *docName;

    docName = "/home/garima/Documents/test-build-desktop/test.xml";
    parseDocument(docName);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::parseDocument(char *docName)
{
    xmlDocPtr doc;
    xmlNodePtr cur;

    doc = xmlParseFile(docName);
    if(doc == NULL)
    {
        qDebug() << "Document is not parsed successfully.";
        return;
    }

    cur = xmlDocGetRootElement(doc);

    if(cur == NULL)
    {
        qDebug() << "Document is empty.";
        xmlFreeDoc(doc);
        return;
    }

    if(xmlStrcmp(cur->name,(const xmlChar *) "story"))
    {
        qDebug() << "document is of wrong type. Story is not a root node.";
        xmlFreeDoc(doc);
        return;
    }

    cur = cur->xmlChildrenNode;

    while(cur != NULL)
    {
        if(xmlStrcmp(cur->name, (const xmlChar *) "storyinfo"))
        {
            parse(doc, cur);
        }

        cur = cur->next;
    }

    xmlFreeDoc(doc);
    return;
}

void MainWindow::parse(xmlDocPtr doc, xmlNodePtr cur)
{
    xmlChar *key;
    cur = cur->xmlChildrenNode;

    while(cur != NULL)
    {
        if(xmlStrcmp(cur->name, (const xmlChar *) "keyword"))
        {
            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
            qDebug() << "Key:" << key;
            xmlFree(key);
        }

        cur = cur->next;
    }

    return;
}

**"Main.cpp" (Main Class) :-**

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
Community
  • 1
  • 1

1 Answers1

4
LIBS += -L/usr/local/lib -libxml2

I think -libxml2 looks for a library called "ibxml2" which is probably not what you want.

If you're after a library called "libxml2" I would try using

LIBS += -L/usr/local/lib -lxml2
Samuel Harmer
  • 4,264
  • 5
  • 33
  • 67