PDA

View Full Version : Struggling with interface classes



JPNaude
23rd June 2010, 09:16
Hi Guys,

I'm running into a problem with a class implementing different interfaces. There is basically 3 libraries: 1 contains the IPlugin interface below, the 2nd contains the IInputParser interface and the third contains the class using these interfaces.

Here is the class and interface definitions. Note that all the SHARED_EXPORT macros are defined in the different libraries as shown below for example:



#if defined(HDL_AUTHOR_PARSER_LIBRARY)
# define HDL_AUTHOR_PARSER_SHARED_EXPORT Q_DECL_EXPORT
#else
# define HDL_AUTHOR_PARSER_SHARED_EXPORT Q_DECL_IMPORT
#endif




class HDL_AUTHOR_PARSER_SHARED_EXPORT HDL_Author_Parser : public IPlugin, public IInputParser
{
Q_OBJECT
Q_INTERFACES(Qtilities::ExtensionSystem::Interface s::IPlugin)
//Q_INTERFACES(FirmwareCore::Interfaces::IInputParse r)

public:
HDL_Author_Parser(QObject* parent = 0);
~HDL_Author_Parser();

// --------------------------------------------
// IInputParser Implementation
// --------------------------------------------
DesignManager* parseDesignFromFile(const QString& fileName) const;
QMap<QString,QString> supportedFileTypes() const;

// --------------------------------------------
// IPlugin Implementation
// --------------------------------------------
bool initialize(const QStringList &arguments, QString *errorString);
bool initializeDependancies(QString *errorString);
void finalize();
double pluginVersion();
QList<double> pluginCompatibilityVersions();
QString pluginPublisher();
QString pluginPublisherWebsite();
QString pluginPublisherContact();
QString pluginDescription();
QString pluginCopyright();
QString pluginLicense();

private:
HDL_Author_ParserData* d;
};




class FIRMWARE_CORE_LIBRARY_SHARED_EXPORT IInputParser {
public:
IInputParser() {}
virtual ~IInputParser() {}

virtual DesignManager* parseDesignFromFile(const QString& fileName) const = 0;
virtual QMap<QString,QString> supportedFileTypes() const = 0;
};




class EXTENSION_SYSTEM_SHARED_EXPORT IPlugin : public QObject
{
Q_OBJECT
Q_ENUMS(PluginState)

public:
IPlugin(QObject* parent = 0) : QObject(parent) {}
virtual ~IPlugin() {}

enum PluginState { Functional, InitializationError, DependancyError };
void setPluginState(PluginState state) { d_state = state; }
PluginState pluginState() { return d_state; }
void setErrorString(const QString& error_string) { d_error_string = error_string; }.
QString errorString() { return d_error_string; }
virtual bool initialize(const QStringList &arguments, QString *errorString) = 0;
virtual bool initializeDependancies(QString *errorString) = 0;
virtual void finalize() { }
virtual double pluginVersion() = 0;
virtual QList<double> pluginCompatibilityVersions() = 0;
virtual QString pluginPublisher() = 0;
virtual QString pluginPublisherWebsite() = 0;
virtual QString pluginPublisherContact() = 0;
virtual QString pluginDescription() = 0;.
virtual QString pluginCopyright() = 0;
virtual QString pluginLicense() = 0;

private:
PluginState d_state;
QString d_error_string;
};


Now when I compile this I get linker errors:


d:/Projects/Qt/FirmwareManagementTool/sources/trunk/build/tmp/HDL_Author_Parser/HDL_Author_Parser.o: In function `IInputParser':
d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:26: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputPars erE'
d:/Projects/Qt/FirmwareManagementTool/sources/trunk/build/tmp/HDL_Author_Parser/HDL_Author_Parser.o: In function `~IInputParser':
d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:27: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputPars erE'
d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:27: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputPars erE'
d:/Projects/Qt/FirmwareManagementTool/sources/trunk/libraries/FirmwareCore/sources/IInputParser.h:27: undefined reference to `_imp___ZTVN12FirmwareCore10Interfaces12IInputPars erE'


I really don't understand why it does not work and I can't see any problems. When the HDL_Author_Parser class does not inherit from the IInputParser class it is not a problem.

Any help would be appreciated.

Thanks,
Jaco

JPNaude
23rd June 2010, 10:24
It seems like I managed to get around the problem but it is really a hack only. It seems like the interface classes are not exported properly when the interface is not used anywhere in the library where it lives.

I the dummy class shown below to the library where the interface classes live and now it works.



class DummyParser : public QObject, public IInputParser, public IOutputParser
{
Q_OBJECT
public:
explicit DummyParser(QObject *parent = 0);

// --------------------------------------------
// IInputParser Implementation
// --------------------------------------------
DesignManager* parseDesignFromFile(const QString& fileName) const { return 0; }
QMap<QString,QString> supportedInputTypes() const { return QMap<QString,QString>(); }

// --------------------------------------------
// IOutputParser Implementation
// --------------------------------------------
bool parseDesignToFile(IDesignManager* design, const QString& fileName) const { return 0; }
QMap<QString,QString> supportedOutputTypes() const { return QMap<QString,QString>(); }

signals:

public slots:
};


Has anybody seen this before?
Thanks
Jaco