9.4 Library Versions

Library version numbering is one area where Mac OS X differs from other Unix variants. In particular, the dynamic linker dyld checks both major and minor version numbers. Also, the manner in which library names carry the version numbers is different. On ELF systems, shared libraries are named with an extension similar to the following:


Typically, a symbolic link is created in the library named libname.so , which points to the most current version of the library. For example, on an ELF system like Solaris, libMagick.so.5.0.44 is the name of an actual library. If this is the latest installed version of the library, you can find symbolic links that point to this library in the same directory. These symbolic links are typically created during the installation process.

In this example, both libMagick.so and libMagick.so.5 are symbolic links that point to libMagick.so.5.0.44 . Older versions of the library may also be present, such as libMagick.so.5.0.42 . However, although older versions of the library may be present, whenever a newer version is installed, the symbolic links are updated to point to the latest version. This works because when you create a shared library, you need to specify the name of the library to be used when the library is called by a program at runtime.

In general, you should keep older versions of libraries around, just in case an application depends on them. If you are certain there are no dependencies, you can safely remove an older version.

On Mac OS X, the libMagick library is named libMagick.5.0.44.dylib , and the symbolic links libMagick.dylib and libMagick.5.dylib point to it. Older versions, such as libMagick.5.0.42.dylib , may also be found in the same directory. One difference that is immediately apparent on Mac OS X systems is that the version numbers are placed between the library name and the .dylib extension rather than at the end of the filename, as on other Unix systems (e.g., libMagick.so.5.0.42 ).

Another difference on Darwin is that the absolute pathname is specified when the library is installed. Thus, ldconfig is not used in Darwin, since paths to linked dynamic shared libraries are included in the executables. On an ELF system, you typically use ldconfig or set the LD_LIBRARY_PATH variable. In Darwin, use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH (see the dyld manpage for more details).

You can link against a particular version of a library by including the appropriate option for cc , such as - lMagick.5.0.42 . Minor version checking is another way that the Mach-O format differs from ELF. To illustrate this, let's revisit Example 9-4, shown earlier in this chapter.

Suppose that the library shown in Example 9-4 is continually improved: minor bugs are fixed, minor expanded capabilities are added, and, in time, major new features are introduced. In each of these cases, you'll need to rename the library to reflect the latest version. Assume that the last version of the library is named libanswer.1.2.5.dylib . The major version number is 1 , the minor revision is 2 , and the bug-fix (i.e., fully compatible) revision number is 5 . Example 9-8 illustrates how to update this library to release libanswer.1.2.6.dylib , which is fully compatible with the release 1.2.5, but contains some bug fixes.

In the makefile shown earlier in Example 9-5, replace the following lines:

 libanswer.dylib: answer.o         $(LD) -dynamiclib -install_name libanswer.dylib \         -o libanswer.dylib answer.o 

with the code shown in Example 9-8.

Example 9-8. Versioning the answer library
 libanswer.dylib: answer.o       $(LD) -dynamiclib -install_name libanswer.1.dylib \             -compatibility_version 1.2 -current_version 1.2.6 \               -o libanswer.1.2.6.dylib $(OBJS)        rm -f libanswer.1.dylib  libanswer.1.2.dylib libanswer.dylib       ln -s libanswer.1.2.6.dylib libanswer.1.2.dylib       ln -s libanswer.1.2.6.dylib libanswer.1.dylib       ln -s libanswer.1.2.6.dylib libanswer.dylib' 

Symbolic links are established to point to the actual library: one link reflects the major revision, one reflects the minor revision, and one simply reflects the name of the library.

The compatibility version number checks that the library used by an executable is compatible with the library that was linked in creating the executable. This is why the phrase compatibility version makes sense in this context.

Mac OS X Panther for Unix Geeks
Mac OS X Panther for Unix Geeks
ISBN: 0596006071
EAN: 2147483647
Year: 2003
Pages: 212

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net