Click to See Complete Forum and Search --> : calling application class method from plugin


freeagle
March 11th, 2008, 06:16 AM
Hello,

I'm having a problem with my plugin platform. I have a main application class, that handles plugin loading and GUI, which is linked into executable. When creating a plugin, I pass a pointer to this class through defined plugin interface. The problem is, that when the plugin is loaded and I call any method of the main class from it, I get unresolved symbol error. I thought that dynamic linking takes care of that, but it doesnt seem to. Do I have to specify some linkage information on every class of the main app? Is there a cross-platform solution to this ( i need to work in win, linux and mac os x)?

Thank you very much

Dalibor

MrViggy
March 11th, 2008, 10:31 AM
It's not a linking problem, in that the function you're calling cannot be found by the linker (dynamically, I'm assuming). Are you sure the function signature is correct (i.e. you're calling the correct function)?

Viggy

freeagle
March 11th, 2008, 11:05 AM
its a runtime error. The plugin is dyn-linked correctly (e.g error free) to my app, but when the function gets called, i get runtime error telling me the symbol could not be resolved. Yes, I think I'm calling the right function. Declaration of the app class is gathered from its header file, I'm not just guessing which function to call.

dalibor

MrViggy
March 11th, 2008, 11:42 AM
Well, all I can say is that either (a) the function is not exported from your library (if you're running on Windows), or (b) there is a typo in your code.

Without an example, I can't say anything more...

Viggy

freeagle
March 12th, 2008, 11:02 AM
This one of my classes from the application:

%Project.h%

class Project;

#ifndef _PROJECT_H_
#define _PROJECT_H_

// platform
#include "Platform.h"

// Qt
#include <QFile>
#include <QDir>
#include <QStringList>
#include <QSettings>


class Project
{
friend class Platform;

// consturctors && destructors
private:
Project(QString& projFile);
~Project();

// getters && setters
public:
QString projectFile() const;

QString projectDir() const;

QSettings* config() const;

QString name() const;

QStringList projectType() const;


// data
private:
QString _projectFile;
QString _projectDir;
QSettings* _config;

// project properties
QString _name;
QStringList _projectType;
};

this class gets linked into an executable, along with some other classes



this is a snippet from the plugin:

// slots
void
ProjectsView::projectOpened(Project* project)
{
_widget->addTopLevelItem(new QTreeWidgetItem(_widget, QStringList(project->name())));
}

it includes Project.h in its associated header file. the calling of name() method fails with this error:
symbol lookup error: /data/School/07-08/Bc/platform/plugins/libbase.so: undefined symbol: _ZNK7Project4nameEv


thanks

dalibor

freeagle
March 13th, 2008, 02:54 PM
just to let you, and maybe the rest of people stuck with similar problem, all I had to do was to declare the method as virtual. Which, if I understand it correctly, placed the entry point of that function into a VTable, which is always only one for a class. So when calling, it gets the entry point from there. Otherwise, the entry point gets statically linked and it doesnt work. Correct me if my understanding of it is wrong please