RejectedSoftware Forums

Sign up

Question about subpackage

In order to understand how subpackage works I have created a simple project.

So, if I set module name:

/* in insects/src/bee.d */
module insect.bee;
...

dmd complains about module bee

$ dub
src/app.d(1,8): Error: module bee is in file 'insects/bee.d' which cannot be read

If I remove module name

/* in insects/src/bee.d */

//module insect.bee;
...

and import just file name:

// in src/app.d 

//import insects.bee;
import bee;

void main() {
  ...

it works.

So, I cannot use module declaration in my subpackage?

Thanks

Re: Question about subpackage

On Tue, 27 Sep 2016 18:56:47 GMT, o3o wrote:

In order to understand how subpackage works I have created a simple project.

So, if I set module name:

/* in insects/src/bee.d */
module insect.bee;
...

dmd complains about module bee

$ dub
src/app.d(1,8): Error: module bee is in file 'insects/bee.d' which cannot be read

If I remove module name

/* in insects/src/bee.d */

//module insect.bee;
...

and import just file name:

// in src/app.d 

//import insects.bee;
import bee;

void main() {
  ...

it works.

So, I cannot use module declaration in my subpackage?

Thanks

The directory structure must correspond to the fully qualified module name in order for the compiler to be able to find it. So in this case you'd have to put the bee.d file in a sub folder src/insects/ instead of directly into src/. It unfortunately creates a bit of redundancy, but there is usually no way around it (always compiling with dub build --combined would also make it work, but that's a rather questionable workaround).

Re: Question about subpackage

On Wed, 28 Sep 2016 12:09:47 GMT, Sönke Ludwig wrote:

The directory structure must correspond to the fully qualified module name in order for the compiler to be able to find it. So in this case you'd have to put the bee.d file in a sub folder src/insects/ instead of directly into src/. It unfortunately creates a bit of redundancy, but there is usually no way around it (always compiling with dub build --combined would also make it work, but that's a rather questionable workaround).

You're right! Actually, in all my projects, the sources of library foo is always in foo/src/foo....

Thanks for your quick response and your great work.