Libraries

Let’s discuss libraries in this lesson.

We'll cover the following...

A collection of compiled modules is called a library. Libraries are not programs themselves; they do not have the main() function. Libraries contain compiled definitions of functions, structs, classes, and other features of modules, which are to be linked later by the linker to produce the program.

We can use dmd’s -lib command line option to create libraries. The following command makes a library that contains the “cat.d” and the “dog.d” modules. The name of the library is specified with the -of switch:

$ dmd animal/cat.d animal/dog.d -lib -ofanimal -w -de

The actual name of the library file depends on the platform. For example, the extension of library files is .a under Linux systems: animal.a.

Once the library is built, it is no longer necessary to specify the “animal/cat.d” and “animal/dog.d” modules individually. The library file is sufficient:

$ dmd deneme.d animal.a -w -de
...