www.digitalmars.com         C & C++   DMDScript  

D - [Bug?] static constructors/destructors in library

reply Marko Nikolic <markoni69 verat.net> writes:
      I have a module that has static constructor and destructor. If I 
link my application with object file then everything is working ok 
(constructor and destructor are called as expected). But if I use lib to 
make library out of that module object file and then link my application 
with such a library then constructor and destructor are not called! I am 
using latest dmd and dm packages (dmd 0.79, dmc 8.38, lib 8.00n) for 

    Here is small example of what I am doing (maybe I am doing something 
wrong since these are my first steps in D):

--- a.d ---
import b;

void main() { printf("Done\n"); }

--- b.d ---
static this() { printf("constructor\n"); }
static ~this() { printf("destructor\n"); }

Now, if I make a.exe with
dmd a.d b.d

or even with
dmd -c b.d
dmd a.d b.obj

everything is as expected.

But if I use:
lib -c test.lib b.obj (or equivalent lib test.lib /c +b,,)
dmd a.d test.lib

then application is linked without errors but when it is started 
constructor and destructor are not called - again without any errors!

Feb 17 2004
parent "Walter" <newshound digitalmars.com> writes:
The problem here is that there's nothing the linker sees that pulls in
b.obj, since nothing in a.obj references it.
Jul 16 2004