www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - imports && -run [Bug?]

reply Andrew Edwards <edwards.ac gmail.com> writes:
module mod;
// import inc; [1]
// import inc: p=print; [1]
// static import inc; [1]

void main()
{
     // import inc: print; // [2]
     print();

     // static import inc; // [3]
     // inc.print();
}

------------------------------
module inc;

/*public*/ void print() // [4]
{
     import std.stdio: writeln;
     writeln("You made it!");
}

------------------------------
compiler: DMD v2.071.0
os: OS X El Capitan (10.11.3)

------------------------------
command: dmd -run mod inc

output:

Undefined symbols for architecture x86_64:
   "_D3inc5printFZv", referenced from:
       __Dmain in mod.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
--- errorlevel 1

None of the variations of imports work when compiled with the -run 
switch but all work perfectly well without it.
May 12 2016
parent reply tsbockman <thomas.bockman gmail.com> writes:
On Friday, 13 May 2016 at 01:16:36 UTC, Andrew Edwards wrote:
 command: dmd -run mod inc

 output:

 Undefined symbols for architecture x86_64:
   "_D3inc5printFZv", referenced from:
       __Dmain in mod.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to 
 see invocation)
 --- errorlevel 1

 None of the variations of imports work when compiled with the 
 -run switch but all work perfectly well without it.
According to the DMD compiler manual, the -run switch only accepts a single source file: -run srcfile args... After the first source file, any further arguments passed to DMD will be interpreted as arguments to be passed to the program being run. Have you tried using DUB? It has lots of convenient features, including a `run` command that supports multiple source files: http://code.dlang.org/docs/commandline#run
May 12 2016
next sibling parent reply Andrew Edwards <edwards.ac gmail.com> writes:
On 5/13/16 3:10 PM, tsbockman wrote:
 On Friday, 13 May 2016 at 01:16:36 UTC, Andrew Edwards wrote:
 command: dmd -run mod inc

 output:

 Undefined symbols for architecture x86_64:
   "_D3inc5printFZv", referenced from:
       __Dmain in mod.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)
 --- errorlevel 1

 None of the variations of imports work when compiled with the -run
 switch but all work perfectly well without it.
According to the DMD compiler manual, the -run switch only accepts a single source file: -run srcfile args... After the first source file, any further arguments passed to DMD will be interpreted as arguments to be passed to the program being run.
Thanks, I guess I just expected it to work the same as rdmd does and didn't even bother trying to look in the manual regarding this. I fail to see why the compiler would be less capable at this task than rdmd. Since it is already build to accept multiple input files and knows more about what's going on during compilation than rdmd will ever know, in does not make sense that it should inferior in this regard: yet rdmd takes one imput file and sorts out all dependencies.
 Have you tried using DUB? It has lots of convenient features, including
 a `run` command that supports multiple source files:
      http://code.dlang.org/docs/commandline#run
I've used dub before but it is not desired for what I'm trying to do. rdmd does the trick. Thank you.
May 12 2016
parent Jacob Carlborg <doob me.com> writes:
On 2016-05-13 08:27, Andrew Edwards wrote:

 I fail to see why the compiler would be less capable at this task than
 rdmd. Since it is already build to accept multiple input files and knows
 more about what's going on during compilation than rdmd will ever know,
 in does not make sense that it should inferior in this regard: yet rdmd
 takes one imput file and sorts out all dependencies.
There's no technical reason why the compiler is not doing this, as far as I know. -- /Jacob Carlborg
May 13 2016
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2016-05-13 08:10, tsbockman wrote:

 According to the DMD compiler manual, the -run switch only accepts a
 single source file:
      -run srcfile args...

 After the first source file, any further arguments passed to DMD will be
 interpreted as arguments to be passed to the program being run.
To elaborate, since the second file "inc" is not passed to the compiler, it will not compile that file, therefore you get linker errors. The solution is to pass all extra files before the -run flag. Even better is to use "rdmd" which will automatically track and compile dependencies. Using rdmd it's enough to pass a single file to compile all dependencies and run the resulting binary: "rdmd mod".
 Have you tried using DUB? It has lots of convenient features, including
 a `run` command that supports multiple source files:
      http://code.dlang.org/docs/commandline#run
Dub is a great tool when a project grows larger than a few files. -- /Jacob Carlborg
May 12 2016
parent zabruk70 <sorry noem.ail> writes:
On Friday, 13 May 2016 at 06:33:40 UTC, Jacob Carlborg wrote:
 Even better is to use "rdmd" which will automatically track and 
 compile dependencies.
but i should warn about annoing bug with local import http://forum.dlang.org/post/mailman.1984.1373610213.13711.digitalmars-d puremagic.com https://issues.dlang.org/show_bug.cgi?id=7016
May 13 2016