www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - rdmd vs dmd WRT static constructors

reply Andrew Edwards <edwards.ac gmail.com> writes:
RDMD does not behave the same as DMD WRT static constructors. The 
following example, extracted form Mike Parker's "Learning D", 
does not produce the same result:

// stat1.d
module stat1;
import std.stdio;
static this() { writeln("stat1 constructor"); }

// stat2.d
module stat2;
import std.stdio;
static this() { writeln("stat2 constructor"); }

// statmain.d
void main() { }

$ rdmd statmain.d stat1.d stat2.d
// outputs nothing...

$ dmd statmain.d stat1 stat2
$ ./statmain
// outputs...
stat1 constructor
stat2 constructor

Bug or intended behaviour?

Thanks,
Andrew
Jul 08 2017
parent reply Mike Parker <aldacron gmail.com> writes:
On Sunday, 9 July 2017 at 02:57:54 UTC, Andrew Edwards wrote:

 $ rdmd statmain.d stat1.d stat2.d
 // outputs nothing...


 Bug or intended behaviour?
rdmd takes the first D file you give it, follows its import tree, and compiles all the modules found there. Anything on the command line after the first source file is treated as a command line argument to the generated program. So stat1.d and stat2.d are never compiled. You'll see if you modify your main function to output the args that it will print the file names you passed. To include stat1.d and stat2.d in the compilation, you'll either have to import them in statmain.d or use the --extra-file command line switch: rdmd --extra-file=stat1.d --extra-file=stat2.d statmain.d
Jul 08 2017
parent Andrew Edwards <edwards.ac gmail.com> writes:
On Sunday, 9 July 2017 at 03:11:17 UTC, Mike Parker wrote:
 On Sunday, 9 July 2017 at 02:57:54 UTC, Andrew Edwards wrote:

 To include stat1.d and stat2.d in the compilation, you'll 
 either have to import them in statmain.d or use the 
 --extra-file command line switch:

 rdmd --extra-file=stat1.d --extra-file=stat2.d statmain.d
Okay, got it... thanks Mike.
Jul 08 2017