PDA

View Full Version : Linking error when using library in other application



JPNaude
20th January 2010, 09:17
Hi

I've been trying to get my head around a linking error for a couple of days now. I have a library which has a QMainWindow derived class. The library builds fine, but when I create an instance of the derived class in a simple example program, the linker fails with the error below. I know what this error means, but I don't see how it applies to my situation:



../../tmp/actionmanagementexample/main.o: In function `Z5qMainiPPc':
d:\ScinericSoftware\Products\Qtilities\trunk\libra ries\ObjManagementLib\examples\ActionManagement/main.cpp:31: undefined reference to `Qtilities::ObjManagement::ExtendedMainWindow::Ext endedMainWindow(QWidget*)'


Here is my main program:



#include <QtGui>
#include <ExtendedMainWindow.h>

using namespace Qtilities::ObjManagement;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

ExtendedMainWindow* mainWindow = new ExtendedMainWindow(0);
mainWindow->show();

return a.exec();
}


and my .pro file:



TARGET = ActionManagement
TEMPLATE = app
SOURCES += main.cpp
LIBS += ../../bin/libObjManagementLib.a
CONFIG += debug


And the ExtendedMainWindow class:



#ifndef OBJMANGEMENTLIBMAINWINDOW_H
#define OBJMANGEMENTLIBMAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class ExtendedMainWindow;
}

namespace Qtilities {
namespace ObjManagement {
struct ExtendedMainWindowData;
class ExtendedMainWindow : public QMainWindow {
Q_OBJECT
public:
ExtendedMainWindow(QWidget *parent = 0);
~ExtendedMainWindow();

protected:
void changeEvent(QEvent *e);

private:
Ui::ExtendedMainWindow *ui;
ExtendedMainWindowData* d;
};
}
}

#endif // OBJMANGEMENTLIBMAINWINDOW_H



And the .cpp implementation of ExtendedMainWindow:



#include "ExtendedMainWindow.h"
#include "ui_ExtendedMainWindow.h"

struct Qtilities::ObjManagement::ExtendedMainWindowData {
ExtendedMainWindowData() { }

};

Qtilities::ObjManagement::ExtendedMainWindow::Exte ndedMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ExtendedMainWindow)
{
ui->setupUi(this);
d = new ExtendedMainWindowData;
}

Qtilities::ObjManagement::ExtendedMainWindow::~Ext endedMainWindow()
{
delete ui;
delete d;
}

void Qtilities::ObjManagement::ExtendedMainWindow::chan geEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


The UI file is just a plain QMainWindow with nothing on it, called ExtendedMainWindow. I don't understand how the library is able to build (which means that it find the implementation of those functions), but linking against it does not work. Creating wit

Any ideas will be greatly appreciated.

Thanks,
Jaco

JPNaude
20th January 2010, 09:20
Ah! Always happens, just when you post something you find the problem...

Apologies, I forgot to export the class.
Thanks
Jaco