On Friday, 11 December 2015 at 03:20:29 UTC, J Smith wrote:
Say I have a project with the files structured like this.

package-name/
    src/
        package-name/
            lib.d
    test/
        testlib.d

How do I make it so that I can import and use the contents of lib.d inside of testlib.d.

As you can tell I'm very new to D, and kind of new to programming. Forgive me for very noob and easy question, but couldn't really find anything out by reading the docs.

In D, directory structure doesn't matter. What matters is module names.

Let's say module name of lib.d is "module a;", and for testlib.d, it is "module b;".

Then you can access whichever you want with dot notation. "a.foo();", "b.var = 5;" etc.

Where directory structure matters is compiling.

dmd main.d src/package-name/lib.d test/testlib.d

Because it is logical to match directory structure and module name, it is done in that way mostly, but there are times you might not want this.

Reply via email to