Clients should be able to use all the minor revisions to the library they’re linked against without relinking. In
general, to use a major revision of a library, the client must be linked against the new version. The client may
also need to be changed to take advantage of new symbols, to adapt its use of symbols that have been
modified, or to not use symbols that are not exported by the new revision.
Note: The header files for your libraries should include only the symbols the libraries’ clients should actually
use. If clients use symbols other than the ones you specify, they limit the compatibility of their products with
new or earlier versions of your libraries.
Specifying Version Information
The filename of a dynamic libraries normally contains the library’s name with the lib prefix and the .dylib
extension. For example, a library called Dynamo would have the filename libDynamo.dylib. However, if
a library may go through one or more revisions after it’s released, its filename must include the major version
number of the revision. Clients linked against libraries whose filename includes the major version number
of the revision never use a new major revision of the library because major revisions are published under
different filenames. This versioning model prevents clients from using library revisions whose API is
incompatible with the API known to the clients.
When you publish a dynamic library intended to have future revisions, you must disclose the library’s major
version number in its filename. For example, the filename for the first version of the Draw library, introduced
in “Defining Client Compatibility” (page 14), could be libDraw.A.dylib. The letter A specifies the major
version number for the initial release. You can use any nomenclature for the major version. For example, the
Draw library could also be named libDraw.1.dylib, or libDraw.I.dylib. The important thing is that
the filenames of subsequent major revisions of the library have different (and preferably incremental) major
version numbers. Continuing the Draw library example, a major revision to the library could be named
libDraw.B.dylib , libDraw.2.dylib, or libDraw.II.dylib. Minor revisions to the library are released
under the same filename used by the previous major revision.
In addition to the major version number, a library has a minor version number. The minor version number
is an incremental number using the format X[.Y[.Z]] , where X is a number between 0 and 65535, and Y
and Z are numbers between 0 and 255. For example, the minor version number for the first release of the
Draw library could be 1.0. To set the minor version number of a dynamic library, use the gcc
-current_version option.
The compatibility version number is similar to the minor version number; it’s set through the gcc
-compatibility_version option. The compatibility version number of a library release specifies the
earliest minor version of the clients linked against that release can use. For instance, the example in “Defining
Client Compatibility” (page 14) indicates that Client 1.1 cannot use versions of the Draw library earlier than
1.2 because they don’t export the draw_polygon function.
Before loading a dynamic library, the dynamic loader compares the current version of the .dylib file in the
user’s file system with the compatibility version of the .dylib file the client was linked against in the
developer’s file system. If the current version is earlier (less) than the compatibility version, the dependent
library is not loaded. Therefore, the launch process (for client applications) or the load process (for client
libraries) is aborted.
16
Managing Client Compatibility With Dependent Libraries
2009-02-26 | © 2009 Apple Inc. All Rights Reserved.
Dynamic Library Design Guidelines