Re: Module static constructor doesn't work?

2019-08-08 Thread Andrey Zherikov via Digitalmars-d-learn
On Thursday, 8 August 2019 at 16:04:33 UTC, a11e99z wrote: On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote: I have the following code: // main.d int main() { import std.stdio; writeln("hello"); return 0; } But if I create library from lib.d first and then link it

Re: Module static constructor doesn't work?

2019-08-08 Thread kinke via Digitalmars-d-learn
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote: But if I create library from lib.d first and then link it with main.d then ctor/dtor are not called: For this to work as expected, the `lib.obj` object file needs to be linked into the final executable. As main.d doesn't need

Re: Module static constructor doesn't work?

2019-08-08 Thread a11e99z via Digitalmars-d-learn
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote: I have the following code: // main.d int main() { import std.stdio; writeln("hello"); return 0; } But if I create library from lib.d first and then link it with main.d then ctor/dtor are not called: $ dmd.exe -lib

Re: Module static constructor doesn't work?

2019-08-08 Thread Dukc via Digitalmars-d-learn
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote: I have the following code: // lib1/lib.d module lib; import std.stdio; static this() { writeln("+" ~ __FILE__); } static ~this() { writeln("-" ~ __FILE__); } // main.d int main() { import std.stdio;

Module static constructor doesn't work?

2019-08-08 Thread Andrey Zherikov via Digitalmars-d-learn
I have the following code: // lib1/lib.d module lib; import std.stdio; static this() { writeln("+" ~ __FILE__); } static ~this() { writeln("-" ~ __FILE__); } // main.d int main() { import std.stdio; writeln("hello"); return 0; } So if I compile lib.d and main.d together