www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to share modules when using -shared?

reply Justin Whear <justin economicmodeling.com> writes:
I'm trying to build components that I can dynamically link and keep 
running into an issue with sharing modules between the host and the 
pluggable components. Assuming a layout like this:

  host.d  -- loads components at runtime
  a.d     -- a module that builds to `a.so`
  b.d     -- a module that builds to `b.so`
  common.d

If a.d and b.d both import common.d, all is well.  If host.d imports 
common.d as well, I get this at runtime: 
Fatal Error while loading 'a.so':
	The module 'common' is already defined in 'host'.

Test session with sources here: http://pastebin.com/LxsqHhJm

Some of this can be worked around by having host.d use its own extern 
definitions, but how does this work with interfaces?  My tests thus far 
have resulted in object invariant failures.
Dec 09 2014
parent "MrSmith" <mrsmith33 yandex.ru> writes:
On Wednesday, 10 December 2014 at 00:44:41 UTC, Justin Whear 
wrote:
 I'm trying to build components that I can dynamically link and 
 keep
 running into an issue with sharing modules between the host and 
 the
 pluggable components. Assuming a layout like this:

   host.d  -- loads components at runtime
   a.d     -- a module that builds to `a.so`
   b.d     -- a module that builds to `b.so`
   common.d

 If a.d and b.d both import common.d, all is well.  If host.d 
 imports
 common.d as well, I get this at runtime:
 Fatal Error while loading 'a.so':
 	The module 'common' is already defined in 'host'.

 Test session with sources here: http://pastebin.com/LxsqHhJm

 Some of this can be worked around by having host.d use its own 
 extern
 definitions, but how does this work with interfaces?  My tests 
 thus far
 have resulted in object invariant failures.
You can have common in separate .so file, or include it in host.
Dec 14 2014