> I have a simple program composed of a main executable and a dynamic
> library (built with -dynamic -dynamiclib). The executable is _not_
[quoted text clipped - 11 lines]
> Is there any way to make dlclose() behave as it does on other Unix
> systems, such as Linux and Solaris?
Are you sure your library is actually being unloaded? Last I knew,
dlclose didn't unload dylibs on Mac OS X.
If you don't have to link against this library at compile time, I'd
suggest building it as a bundle (-bundle) rather than a dylib
(-dynamiclib). Bundles should have the .bundle extension and are
unloadable.
-Eric

Signature
Eric Albert ejalbert@cs.stanford.edu
http://outofcheese.org/
Yuval Kfir - 12 Aug 2005 12:29 GMT
> Are you sure your library is actually being unloaded? Last I knew,
> dlclose didn't unload dylibs on Mac OS X.
[quoted text clipped - 3 lines]
> (-dynamiclib). Bundles should have the .bundle extension and are
> unloadable.
No, in fact, I'm sure it is NOT being unloaded. That is exactly the
problem. So despite documentation to the contrary, dlclose() is
essentially a no-op for .dylib libraries on Mac OS/X? Ugh.
I will look into the .bundle solution. Thank you for the information!
- Yuval
Alwyn - 12 Aug 2005 12:32 GMT
> Are you sure your library is actually being unloaded? Last I knew,
> dlclose didn't unload dylibs on Mac OS X.
Then is the documentation wrong yet again?
> Discussion
> This function decreases the reference count of the image referenced by
[quoted text clipped - 4 lines]
> queried with dlerror.
> See also dlopen, dlerror.
Alwyn
Eric Albert - 12 Aug 2005 18:13 GMT
In article
<dt015a1979-CD8313.12322412082005@text.news.blueyonder.co.uk>,
> > Are you sure your library is actually being unloaded? Last I knew,
> > dlclose didn't unload dylibs on Mac OS X.
[quoted text clipped - 9 lines]
> > queried with dlerror.
> > See also dlopen, dlerror.
You're looking at the Panther man page, not the Tiger one -- the dl*
APIs were rewritten from scratch for Tiger -- but yeah, I think it's
wrong. Unfortunately, unloading dylibs is a lot harder than you might
think.
-Eric

Signature
Eric Albert ejalbert@cs.stanford.edu
http://outofcheese.org/
Alwyn - 12 Aug 2005 18:36 GMT
> You're looking at the Panther man page, not the Tiger one
Dynamic Loader API Reference: Dynamic Loader Compatibility Functions
(Last updated: 2005-06-04)
> -- the dl* APIs were rewritten from scratch for Tiger
So I believe.
> -- but yeah, I think it's
> wrong. Unfortunately, unloading dylibs is a lot harder than you might
> think.
That may well be, but their documentation consistently fails to reflect
the facts.
Alwyn
Alwyn - 12 Aug 2005 18:17 GMT
> Are you sure your library is actually being unloaded? Last I knew,
> dlclose didn't unload dylibs on Mac OS X.
You're quite right, it doesn't on Mac OS 10.4.2. This is very
surprising, in the light of the recently updated documentation at:
<http://developer.apple.com/documentation/DeveloperTools/Conceptual/Dynam
icLibraries/index.html#//apple_ref/doc/uid/TP40001869>
> The client must call dlclose when it¹s finished using the dynamically loaded
> library (for example, when the module that opened the library has finished
> its task).
...
> Calls to dlclose decrement the library handle¹s reference count. Therefore,
> you must balance every call to dlopen with a call to dlclose. When the
> reference count for a library handle reaches 0, the dynamic loader may remove
> the library from the address space of the application.
The wording "may remove" above is interesting, however.
Alwyn