Scope of D packages

cym13 via Digitalmars-d-learn digitalmars-d-learn at
Fri Dec 18 16:46:12 PST 2015

On Saturday, 19 December 2015 at 00:09:16 UTC, Basile B. wrote:
> On Friday, 18 December 2015 at 23:20:34 UTC, Jakob Jenkov wrote:
>> I'm coming from Java where "packages" are not that much more 
>> than directories. Each class can be exposed or hidden inside a 
>> package etc.
>> In Java it is common that an API consists of many packages and 
>> subpackages. All classes are simply wrapped up in a JAR (Zip) 
>> file, and then they can be used as a library.
>> What is common in D?
>> Does a library have all its classes inside the same package 
>> (same directory) ? Or can you have multiple packages / 
>> subpackages inside the same library *and* same source root?
> each sub directory in a package is also a package
> lib/package.d : allow to put all the lib modules as public 
> import
> lib/module1.d : this is module 1 from package lib
> lib/module2.d : this is module 2 from package lib
> lib/sub1/package.d : allow to put all the lib.sub1 modules as 
> public import
> lib/sub1/module1: this is module 1 from package lib.sub1
> lib/sub1/module2: this is module 2 from package lib.sub1
> but when you compile 'lib' library it's a monolithic *.a or 
> *.lib file, which still requires the sources.
> look at 
> structure for example.

To be exact it doesn't need the sources, it needs the function 
signatures and type definitions so the equivalent of C header 
files. If you don't want to share the full sources with your 
library you can generate those header files automatically using 
the -H flag in dmd. It will produce a "D interface" file with a 
"di" extension.

More information about the Digitalmars-d-learn mailing list