www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why does file order matters when using -run option?

reply Marc <jckj33 gmail.com> writes:
assume the files:

app.d

 void main() {
   import myModule : foo;
    writeln(foo(...));

 }
myModule.d module myModule;
 int foo(int n) { .... }
the following fail:
 dmd -run app.d mymodule.d
give error like this:
 Error: module `myModule` is in file 'myModule.d' which cannot 
 be read
but this doesn't fail:
 dmd app.d mymodule.d && app
Why does -run fail here? I thought it was a shorthand to this batch:
 dmd app.d mymodule.d
 app.exe
 del app.exe
Mar 14 2018
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 14 March 2018 at 14:44:24 UTC, Marc wrote:
 Why does -run fail here? I thought it was a shorthand to this 
 batch:
Check the help text: $ dmd -h dmd [<option>...] -run <file> [<arg>...] <arg> Argument to pass when running the resulting program Notice that there's only one file there. Everything after it is passed as args to the resulting program. So dmd -run cannot support multiple D files. Though, with the new `-i` option you might be able to get it to infer modules. dmd -i -run file_with_main.d args_to_main....... and if it can locate the other modules automatically it should bring them in there.
Mar 14 2018
prev sibling parent Seb <seb wilzba.ch> writes:
On Wednesday, 14 March 2018 at 14:44:24 UTC, Marc wrote:
 assume the files:

 app.d

 void main() {
   import myModule : foo;
    writeln(foo(...));

 }
myModule.d module myModule;
 int foo(int n) { .... }
the following fail:
 dmd -run app.d mymodule.d
give error like this:
 Error: module `myModule` is in file 'myModule.d' which cannot 
 be read
but this doesn't fail:
 dmd app.d mymodule.d && app
Why does -run fail here? I thought it was a shorthand to this batch:
 dmd app.d mymodule.d
 app.exe
 del app.exe
Not even that dmd mymodule.d -run app.d works and dmd -i -run app.d works too. However, at the moment -run needs to be the last parameter. That's a more or less arbitrary restriction. And no one has lifted it (yet). Though there's a bit of work on that front: https://github.com/dlang/dmd/pull/7927 The main problem is that the arguments after -run module are passed to the program and thus -run can be ambiguous.
Mar 14 2018