Introduction to Libraries in GNAT (GNAT User’s Guide for Native Platforms)

#### 3.9.1 Introduction to Libraries in GNAT ¶

A library is, conceptually, a collection of objects which does not have its own main thread of execution but instead provides certain services to the applications that use it. A library can be either statically linked with the application, in which case its code is directly included in the application, or, on platforms that support it, be dynamically linked, in which case its code is shared by all applications making use of this library.

GNAT supports both types of libraries. In the static case, you can provide the compiled code in different ways. The simplest approach is to directly provide the set of objects resulting from compilation of the library source files. Alternatively, you can group the objects into an archive using whatever commands are provided by the operating system.

In the GNAT environment, a library has these components:

- Source files,
- `ALI` files (see The Ada Library Information Files), and
- Object files, an archive, or a shared library.

A GNAT library may expose all its source files, which is useful for documentation purposes. Alternatively, it may expose only the units needed by an external user to make use of the library, in other words, the specs reflecting the library services along with all the units needed to compile those specs, which can include generic bodies or any body implementing an inlined routine. In the case of ‘stand-alone libraries’ those exposed units are called ‘interface units’ (Stand-alone Ada Libraries).

All compilation units comprising an application, including those in a library, need to be elaborated in an order partially defined by Ada’s semantics. GNAT computes the elaboration order from the `ALI` files and this is why they constitute a mandatory part of GNAT libraries. ‘Stand-alone libraries’ are the exception to this rule because a specific library elaboration routine is produced independently of the application(s) using the library.