選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

40 行
1.8KB

  1. A *Hello, World* Library
  2. ########################
  3. Creating a single application is fun, but what if we want to create code that
  4. we can distribute and reuse across other packages and projects? That's what
  5. *libraries* are for.
  6. You may notice something strange: This page is much shorter than the previous.
  7. What gives?
  8. It turns out that we've already covered all the material to make a library in
  9. the page on creating a :doc:`Hello, world! executable <hello-world>`. As soon
  10. as we created the ``strings.hpp`` file, our project had become a library. When
  11. we added a ``strings.cpp`` file to accompany it, our library became a *compiled*
  12. library.
  13. The ``hello-world.main.cpp`` file is expressly *not* considered to be part of a
  14. library, as it is specifically designated to be an application entry point,
  15. and source files of such kind are not part of a library.
  16. Before continuing on, note the following about creating a library that wasn't
  17. specifically addressed in the prior example:
  18. #. The *source roots* of a library are added to the compiler's ``#include``
  19. search-path. In our example, this is only the ``src/`` directory of the
  20. project.
  21. #. ``dds`` also supports a top-level directory named ``include/``. Both
  22. ``include/`` and ``src/`` may be present in a single library, but there are
  23. some important differences. Refer to :ref:`pkgs.lib-roots` in the layout
  24. guide.
  25. #. A single *library root* may contain any number of applications defined in
  26. ``.main`` files, but a *library root* will correspond to exactly *one*
  27. library. Defining additional libraries requires additional packages or
  28. adding multiple library roots to a single package.
  29. .. seealso::
  30. Like flossing, we all know we *should* be writing tests, but it can be such
  31. a hassle. Fortunately, ``dds`` makes it simple. Read on to:
  32. :doc:`hello-test`.