A Hello, World Library¶
Creating a single application is fun, but what if we want to create code that we can distribute and reuse across other packages and projects? That’s what libraries are for.
You may notice something strange: This page is much shorter than the previous. What gives?
It turns out that we’ve already covered all the material to make a library in
the page on creating a Hello, world! executable. As soon
as we created the
strings.hpp file, our project had become a library. When
we added a
strings.cpp file to accompany it, our library became a compiled
hello-world.main.cpp file is expressly not considered to be part of a
library, as it is specifically designated to be an application entry point,
and source files of such kind are not part of a library.
Before continuing on, note the following about creating a library that wasn’t specifically addressed in the prior example:
The source roots of a library are added to the compiler’s
#includesearch-path. In our example, this is only the
src/directory of the project.
ddsalso supports a top-level directory named
src/may be present in a single library, but there are some important differences. Refer to Library Roots in the layout guide.
A single library root may contain any number of applications defined in
.mainfiles, but a library root will correspond to exactly one library. Defining additional libraries requires additional packages or adding multiple library roots to a single package.
Like flossing, we all know we should be writing tests, but it can be such
a hassle. Fortunately,
dds makes it simple. Read on to:
A Hello, World Test.