Next: Creating a Stand-alone Library to be used in a non-Ada context, Previous: Introduction to Stand-alone Libraries, Up: Stand-alone Ada Libraries
GNAT's Project facility provides a simple way of building and installing
stand-alone libraries; see Stand-alone Library Projects.
To be a Stand-alone Library Project, in addition to the two attributes
that make a project a Library Project (Library_Name
and
Library_Dir
; see Library Projects), the attribute
Library_Interface
must be defined. For example:
for Library_Dir use "lib_dir"; for Library_Name use "dummy"; for Library_Interface use ("int1", "int1.child");
Attribute Library_Interface
has a non-empty string list value,
each string in the list designating a unit contained in an immediate source
of the project file.
When a Stand-alone Library is built, first the binder is invoked to build
a package whose name depends on the library name
(b~dummy.ads/b in the example above).
This binder-generated package includes initialization and
finalization procedures whose
names depend on the library name (dummyinit
and dummyfinal
in the example
above). The object corresponding to this package is included in the library.
You must ensure timely (e.g., prior to any use of interfaces in the SAL)
calling of these procedures if a static SAL is built, or if a shared SAL
is built
with the project-level attribute Library_Auto_Init
set to
"false"
.
For a Stand-Alone Library, only the ALI files of the Interface Units
(those that are listed in attribute Library_Interface
) are copied to
the Library Directory. As a consequence, only the Interface Units may be
imported from Ada units outside of the library. If other units are imported,
the binding phase will fail.
The attribute Library_Src_Dir
may be specified for a
Stand-Alone Library. Library_Src_Dir
is a simple attribute that has a
single string value. Its value must be the path (absolute or relative to the
project directory) of an existing directory. This directory cannot be the
object directory or one of the source directories, but it can be the same as
the library directory. The sources of the Interface
Units of the library that are needed by an Ada client of the library will be
copied to the designated directory, called the Interface Copy directory.
These sources include the specs of the Interface Units, but they may also
include bodies and subunits, when pragmas Inline
or Inline_Always
are used, or when there is a generic unit in the spec. Before the sources
are copied to the Interface Copy directory, an attempt is made to delete all
files in the Interface Copy directory.
Building stand-alone libraries by hand is somewhat tedious, but for those occasions when it is necessary here are the steps that you need to perform:
init
and final
procedures. For example:
gnatbind -n int1.ali int2.ali -Lsal1
gcc -c b~int2.adb
init
(and possibly
final
) procedures for automatic initialization (and finalization).
The built library should be placed in a directory different from
the object directory.
ALI
files of the interface to the library directory,
add in this copy an indication that it is an interface to a SAL
(i.e. add a word SL on the line in the ALI file that starts
with letter “P”) and make the modified copy of the ALI file
read-only.
Using SALs is not different from using other libraries (see Using a library).