www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Object.factory fails for static libraries

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

I try to create objects by using the factory method in a static 
library scenario.


file base.d
-------------------------------
module base;
class Base { }

Object createObject(string name)
{
   return Object.factory(name);
}
-------------------------------


file child.d
-------------------------------
module child;
import base;
class Child: Base { }
-------------------------------

file main.d
-------------------------------
import base, child;

void main()
{
     import std.traits: fullyQualifiedName;
     assert( Object.factory(fullyQualifiedName!Child) !is null);
     assert( createObject(fullyQualifiedName!Base) !is null);
     assert( createObject(fullyQualifiedName!Child) !is null);
}
-------------------------------

My windows batch file looks like this:
dmd base -lib
dmd child -lib base.lib
dmd main base.lib child.lib
main
PAUSE

All assertions fails. Should this work, or is this a restriction
of object.factory?

Kind regards
André
Jun 04 2016
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Saturday, 4 June 2016 at 16:12:04 UTC, Andre Pany wrote:
 Hi,

 I try to create objects by using the factory method in a static 
 library scenario.

 ...
 My windows batch file looks like this:
 dmd base -lib
 dmd child -lib base.lib
 dmd main base.lib child.lib
 main
 PAUSE

 All assertions fails. Should this work, or is this a restriction
 of object.factory?

 Kind regards
 André
I just validated, the same issue also occurs on ubuntu linux with the recent dmd compiler. The api for Object.factory does neither say whether this should work or not. Kind regards André
Jun 05 2016
parent Andre Pany <andre s-e-a-p.de> writes:
On Sunday, 5 June 2016 at 08:40:18 UTC, Andre Pany wrote:
 On Saturday, 4 June 2016 at 16:12:04 UTC, Andre Pany wrote:
 Hi,

 I try to create objects by using the factory method in a 
 static library scenario.

 ...
I just validated, the same issue also occurs on ubuntu linux with the recent dmd compiler. The api for Object.factory does neither say whether this should work or not. Kind regards André
Issue https://issues.dlang.org/show_bug.cgi?id=16124 created. Kind regards André
Jun 05 2016