开发者

[windows] back linking

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("Sh开发者_如何学Pythonared 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜