www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Want a module to import from a sister directork; How?

reply jwatson-CO-edu <real.name colorado.edu> writes:
I have the following directory structure:
```
ANN/
     ANN/mathkit/
         ANN/mathkit/package.d
     ANN/utils/
         ANN/utils/package.d
     ANN/MLP.d
```

I have the following in "ANN/mathkit/package.d":

```d
module ANN.mathkit;
//...
/// Local Imports ///
import ANN.utils;
//...
```

I have the following in "ANN/MLP.d":

```d
import mathkit;
//...
void main(){ /* ... */ }
```

When I
`rdmd MLP.d`

I get the following error:
```
mathkit/package.d(7): Error: unable to read module `utils`
mathkit/package.d(7):        Expected 'ANN/utils.d' or 
'ANN/utils/package.d' in one of the following import paths: // ...
```

How do I build my project with these dependencies?:
```
utils --> mathkit --> MLP
     \                 ,^
      `---------------'
```

Must I choose a different structure?
Should I be using DUB?
Feb 14 2023
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
I think you need to do:

```
rdmd MLP.d -I ANN/
```

Basically you need to tell the compiler where your imported 
packages are
Feb 14 2023
parent reply jwatson-CO-edu <real.name colorado.edu> writes:
On Tuesday, 14 February 2023 at 17:56:39 UTC, ryuukk_ wrote:
 I think you need to do:

 ```
 rdmd MLP.d -I ANN/
 ```

 Basically you need to tell the compiler where your imported 
 packages are
This did the trick. I did not need it when `utils` was the only local import, but I suppose the compiler needs a little more help when sibling packages depend on each other.
Feb 14 2023
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
Glad it worked!

I wonder why DMD doesn't just parse the import and follow its 
path since module name must correspond to its path

Does anyone know?
Feb 14 2023
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Tuesday, 14 February 2023 at 21:23:26 UTC, ryuukk_ wrote:
 module name must correspond to its path
this is not true.
Feb 14 2023
parent ryuukk_ <ryuukk.dev gmail.com> writes:
On Tuesday, 14 February 2023 at 21:55:24 UTC, Adam D Ruppe wrote:
 On Tuesday, 14 February 2023 at 21:23:26 UTC, ryuukk_ wrote:
 module name must correspond to its path
this is not true.
I thought it had to match, that's interesting
Feb 14 2023