views:

40

answers:

1

Hi all.

There is shared class. Declarator is in shared header, implementation is in main program. Main program load DLL and exec some function from it, function create object of shared class.

Test code:

shared_header.h:

#include<stdio.h>
class sharedClass{
public:
sharedClass();
};

plugin.cpp -> libplugin.dll

#include"shared_header.h"
extern "C"
void loader(){
printf("Plugin is loaded!\n");
new sharedClass;
}

base.cpp -> base.exe

#include"shared_header.h"
sharedClass::sharedClass(){
printf("Shared class is loaded!\n");
}

int main(){
/*
some actions to load libplugin.dll and exec function loader
*/
return 0;}

So, I want see

Plugin is loaded!
Shared class is loaded!

And it works on Linux. But while I link libplugin.dll on Windows I have error "undefined refernce to sharedClass::sharedClass()". How I need link program and plugin to use this way?

PS. Mingw, stable version.

PPS. I'm so sorry for my terrible English.

+1  A: 

Windows DLLs are non exactly the same thing as UNIX/Linux shared objects.

On Windows, DLLs must be fully linked and have all their references defined. Therefore, as your file plugin.cpp references the sharedClass constructor, the linker will require that this constructor is defined and available to create the DLL. It is not possible to provide it in the executable that loads the DLL.

On UNIX/Linux, shared objects behave differently. Their dependencies are solved when they are loaded by the executable. Therefore, the executable can provide some of the functions needed by the shared object.

Didier Trosset
Yes, but as I know, method to simulate same behaviour on windows exists...
Staseg
I don't know about such method. You could always do things "by hand". I mean defining a function pointer for your missing constructor, and in the loading function of the DLL, you will have to load the DLL (the EXE) that contains it, and initialize the function pointer with it.
Didier Trosset