> I have the following situation:
>
[quoted text clipped - 10 lines]
>
> What gives?
I have never really programmed dynamic libraries on Mac OS X, but I
would _guess_ that the cause of this is that the Dynamic linker does not
use the file names to check whether a given library already is loaded:
<http://developer.apple.com/documentation/DeveloperTools/Conceptual/Dynam
icLibraries/index.html> states:
"The static linker records the filenames of each of the dependent
libraries at the time the application is linked. This filename is
known as the dynamic library¹s install name. The dynamic loader uses
the application¹s dependent libraries¹ install names to locate them
in the file system"
<http://developer.apple.com/documentation/DeveloperTools/Reference/MachOR
eference/Reference/reference.html#//apple_ref/c/func/dlopen> states
about dlopen:
"This function examines the Mach-O file specified by path. If the
image is compatible with the current process and has not already
been loaded into the process, the image is loaded and linked. If the
image contains initializer functions, they are executed before this
function returns."
Note the phrase "If the _image_ [...] has not already been loaded into
the process". I would guess this is _not_ equivalent to: "If the _file_
[...] has not already been loaded into the process".
I guess this is done to make the system load a library only once, even
if multiple copies are opened, or if it is opened using multiple paths.
That way, applications can ship with their own copy of the library
without incurring memory overhead. There still is disk overhead, but
disk is so cheap nowadays that disk overhead is not considered a real
issue.
Reinder
shai@waves.com - 27 Jun 2006 07:00 GMT
> Note the phrase "If the _image_ [...] has not already been loaded into
> the process". I would guess this is _not_ equivalent to: "If the _file_
> [...] has not already been loaded into the process".
Thanks Reinder, This is also the conclusion I reached. Apparently the
DLL have an "inner name" that uniquely identifies them. This name can
be changed with install_name_tool.
Thanks again,
Shai