• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# sharing a static member between .dll's

## Recommended Posts

well.. I have an abstract plugin class in one .dll file and I want to create a real class out of that one in another .dll file when I compile the plugin the linker complains that the cPluginBase::Tools is undefind or something like that if I remove that line everything works perfect.
// -- a tool structure

struct sTools {

// here is some different type of functions/members

// the plugins may acces

cTextureManager *TextureManager;
...

};

// -- in main.dll I have this abstract class

class DLL_API cPluginBase {

// some usefull stuff

public:

// define the tools so that the plugins can acces some

// tool functions through Tools.SomeFunction(...);

static sTools Tools;

// virtual functions

...

};

// -- defined in the .cpp file

sTools cPluginBase::Tools;

// -- this is defined in my plugin.dll file

class DLL_API cMyNewPlugin : public cPluginBase {
public:

// well the real implementation of the virtual functions

...
};


I want to use this so I can add pointers to something to the cPluginBase::Tools.somepointer; e.g. cPluginBase::Tools.TextureManager = RenderSystem->GetTextureManager(); at the moment I have to add the textuer manager to every plugin, like this: for( p=each plugin in list) { p->AttachTextureManager( RenderSystem->GetTextureManager() ); }

##### Share on other sites
You need to export the static variable too, like this

// -- defined in the .cpp DLL_API filesTools cPluginBase::Tools;

##### Share on other sites
I have now tried to do that.. but it still doesn''t work.

##### Share on other sites
Have you tried exporting the declaration for the sTools structure? You say it has functions in it. Unless they are all inlined, it needs to be exported\imported as well as the static instance in the translation unit.

Hope that''s it.

- Jason Citron
- Team nine:14, System Architect
- www.nine14.net
--------------------------------------------------
Checkout the prototype of Fates Forgiven at www.fatesforgiven.com