www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Relative imports and separate compilation

reply "Atila Neves" <atila.neves gmail.com> writes:
I've gone on TDPL and the language reference here but still don't 
get relative imports. I've isolated it to this:

./package1/package2/foo.d:
import std.stdio;
void doFoo() {
     writeln("Foo!");
}

./main.d:
import package1.package2.foo;
void main() {
     doFoo();
}

This works:
dmd -c main.d
dmd -c package1/package2/foo.d
dmd main.o foo.o

This does not:
dmd main.d package1/package2/foo.d
main.d(1): Error: module foo from file package1/package2/foo.d 
must be imported as module 'foo'

The only way I know of to make it work in the 2nd case is to use 
a module declaration at the top of foo. Which is what I've been 
doing so far.

How to relative imports actually work?

Atila
Aug 31 2013
parent reply "Dicebot" <public dicebot.lv> writes:
On Saturday, 31 August 2013 at 09:29:16 UTC, Atila Neves wrote:
 How to relative imports actually work?

 Atila
Actually for me it looks like it is a bug in automatic module name deduction. It should always use full qualified name built from directory path from closest import folder (set by -I , current working directory by default) to actual module file. So behavior observed in separate compilation case is correct one - don't know what actually happens in second case.
Aug 31 2013
parent "Atila Neves" <atila.neves gmail.com> writes:
I wouldn't mind so much if just "regularly" compiling, just do 
each file in turn. The problem is this how rdmd calls dmd and 
then things don't work as they should.


On Saturday, 31 August 2013 at 12:06:00 UTC, Dicebot wrote:
 On Saturday, 31 August 2013 at 09:29:16 UTC, Atila Neves wrote:
 How to relative imports actually work?

 Atila
Actually for me it looks like it is a bug in automatic module name deduction. It should always use full qualified name built from directory path from closest import folder (set by -I , current working directory by default) to actual module file. So behavior observed in separate compilation case is correct one - don't know what actually happens in second case.
Sep 03 2013