Local libraries/packages with dub: How?

rikki cattermole rikki at cattermole.co.nz
Tue Dec 1 07:39:31 UTC 2020


On 01/12/2020 7:39 PM, z wrote:
> On Tuesday, 1 December 2020 at 04:50:03 UTC, rikki cattermole wrote:
>> ...
> 
> What puzzles me is that the dependencies are indeed declared, but "dub 
> describe" refuses to recognize the dependencies and "dub build" fails.
> "dub list" does recognize the root folder, but trying to get a 
> subpackage to import another fails because the dependency isn't 
> imported.(dmd only sees the "source" and phobos/runtime import paths)
> 
> The root dub.sdl roughly contains this :
>> name "fldr"
>> dependencies "fldr:spkg1" "fldr:spkg2" "fldr:spkg3" // tried with and 
>> without "fldr:"

That isn't right.

dependency "fldr:spkg1" version="*"
dependency "fldr:spkg2" version="*"
dependency "fldr:spkg3" version="*"

>> subPackage "./spkg1/"
>> subPackage "./spkg2/"
>> subPackage "./spkg3/"

>> targetType "none"

That probably isn't what you want. Either library or executable.
Either that, or you shouldn't be adding the dependencies.

> While for example, "spkg3"'s dub.sdl contains this :
>>> name "spkg3"
>>> dependencies "fldr:spkg2"

dependency "fldr:spkg2" version="*"

>   And its source/*.d file contains this :
>>>> import std.stdio, fldr.spkg2; //tried with and without "fldr."
>>>> void main() {writeln(«function from spkg2»)}

Don't forget to specify the module name. Every file should declare its 
module full package + module name.

So in this case ``module fldr.spkg2;``.


More information about the Digitalmars-d-learn mailing list