Thread overview
Error: circular initialization dependency with module actor
Jan 15, 2007
orgoton
Jan 15, 2007
Orgoton
Jan 15, 2007
BCS
Jan 15, 2007
orgoton
Jan 15, 2007
BCS
Jan 16, 2007
kenny
Jan 15, 2007
Alexander Panek
January 15, 2007
I have two modules mutually dependent, that means, module actor need module queue which needs module actor. It all went fine with older compilers, but with DMD1.0 I get "Error: circular initialization dependency with module actor" when I try to run the program. How can I fix this?
January 15, 2007
orgoton schrieb:
> I have two modules mutually dependent, that means, module actor need module queue which needs module actor. It all went fine with older compilers, but with DMD1.0 I get "Error: circular initialization dependency with module actor" when I try to run the program. How can I fix this?

remove one of the module ctors ("static this()").

http://www.digitalmars.com/d/module.html
see section: Order of Static Construction
January 15, 2007
Queue (class) has
"public Queue AIQ;"
defined at the end of the module file. This Queue is used on the default
constructor of Actor (a class). There is no static constructor on Actor. The only
static thing on Queue is the symbol above. Queue however must store a list of
Actor's, hence it has an array of Actor. That is a private member of the Queue
class. Is this the origin of "Error: circular initialization dependency with
module actor"? Why didn't I have this error with previous versions?
January 15, 2007
Reply to Orgoton,

> Queue (class) has
> "public Queue AIQ;"
> defined at the end of the module file. This Queue is used on the
> default
> constructor of Actor (a class). There is no static constructor on
> Actor. The only
> static thing on Queue is the symbol above. Queue however must store a
> list of
> Actor's, hence it has an array of Actor. That is a private member of
> the Queue
> class. Is this the origin of "Error: circular initialization
> dependency with
> module actor"? Why didn't I have this error with previous versions?

Are you using code coverage (the -cov flag)?


January 15, 2007
orgoton wrote:
> I have two modules mutually dependent, that means, module actor need module
> queue which needs module actor. It all went fine with older compilers, but
> with DMD1.0 I get "Error: circular initialization dependency with module
> actor" when I try to run the program. How can I fix this?

The easiest and cleanest way would be to put the contents of those modules into one file.
January 15, 2007
Orgoton schrieb:
> Queue (class) has
> "public Queue AIQ;"
> defined at the end of the module file. This Queue is used on the default
> constructor of Actor (a class). There is no static constructor on Actor. The only
> static thing on Queue is the symbol above. Queue however must store a list of
> Actor's, hence it has an array of Actor. That is a private member of the Queue
> class. Is this the origin of "Error: circular initialization dependency with
> module actor"? Why didn't I have this error with previous versions?

All static ctor in a module have the same effect (module or class).

The message indicates that there is a dependency problem related to static ctors.

I try to explain what I understand:
Before main is run, an algorithm tries to run all the existing static ctors.
For each module, there is a list of all contained static ctors and a
list of dependencies (the imports).
It goes to the first modules and calls first recursively all modules
that are listed in the dependencies. If it detects a circular
dependency, the error is thrown.

So, if you use other modules that include your modules or changed imports or you added static ctors, the behaviour can change.

Tip:
If you use static ctors, be careful with you imports.

Can you reproduce, that this behaviour changed between DMD 1.00 the version before?


January 15, 2007
== Quote from BCS (ao@pathlink.com)'s article
> Reply to Orgoton,
> > Queue (class) has
> > "public Queue AIQ;"
> > defined at the end of the module file. This Queue is used on the
> > default
> > constructor of Actor (a class). There is no static constructor on
> > Actor. The only
> > static thing on Queue is the symbol above. Queue however must store a
> > list of
> > Actor's, hence it has an array of Actor. That is a private member of
> > the Queue
> > class. Is this the origin of "Error: circular initialization
> > dependency with
> > module actor"? Why didn't I have this error with previous versions?
> Are you using code coverage (the -cov flag)?

Yes, I am. I mean, I was. I removed the option and the program goes just fine. Thanks for the tip :P
January 15, 2007
Reply to Orgoton,

> == Quote from BCS (ao@pathlink.com)'s article
> 
>> Reply to Orgoton,
>> 
>>> Queue (class) has
>>> "public Queue AIQ;"
>>> defined at the end of the module file. This Queue is used on the
>>> default constructor of Actor (a class). There is no static constructor on Actor. The only static thing on Queue is the symbol above. Queue however must store a list of Actor's, hence it has an array of Actor. That is a private member of the Queue class. Is this the origin of "Error: circular initialization dependency with module actor"? Why didn't I have this error with previous versions?
>>>
>> Are you using code coverage (the -cov flag)?
>> 
> Yes, I am. I mean, I was. I removed the option and the program goes
> just fine. Thanks for the tip :P
> 


That is a big problem (bug?) in DMD, -cov adds a static this that has dependencies (and shoudn't).


January 16, 2007
I have circular dependencies in my code too. I think I solved it with "private import" -- and I also am using -cov (and that generates different linking errors for me, lol)

orgoton wrote:
> == Quote from BCS (ao@pathlink.com)'s article
>> Reply to Orgoton,
>>> Queue (class) has
>>> "public Queue AIQ;"
>>> defined at the end of the module file. This Queue is used on the
>>> default
>>> constructor of Actor (a class). There is no static constructor on
>>> Actor. The only
>>> static thing on Queue is the symbol above. Queue however must store a
>>> list of
>>> Actor's, hence it has an array of Actor. That is a private member of
>>> the Queue
>>> class. Is this the origin of "Error: circular initialization
>>> dependency with
>>> module actor"? Why didn't I have this error with previous versions?
>> Are you using code coverage (the -cov flag)?
> 
> Yes, I am. I mean, I was. I removed the option and the program goes just fine.
> Thanks for the tip :P