Relative imports and separate compilation

Atila Neves atila.neves at gmail.com
Sat Aug 31 02:29:14 PDT 2013


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


More information about the Digitalmars-d-learn mailing list