How does import work?

Jens Mueller jens.k.mueller at gmx.de
Tue Oct 19 02:04:03 PDT 2010


Hi,

I have a simply example using imports that confuses me. Unfortunately I
cannot find explanation on the web site.
File a.d:
module a;

// some import here
//import std.conv;

File b.d:
module b;
import a;

void main() {
}

I do a
$ dmd -run b.d
and that works as expected.
If I commented in 'import std.conv;' in file a.d and do
$ dmd -run b.d
linking fails with
"b.o:(.data+0xc): undefined reference to `_D1a12__ModuleInfoZ'"

I figured out that I need to add a.d like this
$ dmd a.d -run b.d
Because the ModuleInfo for a.d needs to be generated.

So much for my limited understanding.
In my use case I want to do unit testing like this
$ dmd -unittest -run b.d

It seems that I always have to built a library to make sure that an
import works. Can somebody explain the rational behind that? What is
ModuleInfo? And why is it needed? How can I make the unit testing work
per module? How do you do it?
I think I missed something essential about imports.

Jens


More information about the Digitalmars-d mailing list