Shared Libraries Versus Loadable Modules
The Executable and Linking Format (ELF), developed by the Unix System Laboratories, is common in the Unix world. On ELF systems, there is no distinction between shared libraries and loadable modules; shared code can be used as a library for dynamic loading. ELF is the default binary format on Linux, Solaris 2.x, and SVR4. Since these systems cover a large share of the Unix base, most Unix developers have experience on ELF systems. Thus, it may come as a surprise to experienced Unix developers that shared libraries and loadable modules are not the same on Mac OS X. This is because the binary format used in Mac OS X is Mach-O, which is different from ELF.
Mach-O shared libraries have the file type
MH_DYLIB
and the .dylib
(dynamic library) suffix and can be linked to with static linker
flags. So, if you have a shared library named
libcool.dylib, you can link to this library by
specifying the -lcool flag. Although shared
libraries cannot be loaded dynamically as modules, they can be loaded
through the dyld API (see the manpage for
dyld, the dynamic link editor). It is important
to point out that shared libraries cannot be unloaded.
Loadable modules,
called bundles
in Mac OS
X, have the file type
MH_BUNDLE
. Most Unix-based software ports usually
produce bundles with a
.so
extension, for the sake of
consistency across platforms. Although Apple recommends giving
bundles a .bundle extension, it
isn’t mandatory.
Warning
You cannot link directly ...
Get Mac OS X for Unix Geeks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.