More geekery...
Oct. 4th, 2007 08:44 pmMacOS X has an extended concept of the dynamic library, called a framework. Inherited from NeXT, it incorporates headers, libraries, and documentation into one directory structure. You can move the one directory around, and not lose integrity between the bits and pieces. Further, it supports multiple versioning within the one structure, avoiding DLL Hell issues. Great concept.
Does not play well with Linux build approaches.
There's one weakness in the OS X linker (dyld) - it wants paths to the dynamic libraries themselves, not search paths. Yup, static paths. Once you link in a library, even dynamically, you're expected never to move it. Kind of lame, if you ask me, but given that frameworks offer robust versioning control, it makes the reasons for moving libraries around in most use cases less necessary.
To support floating dynamic libraries, Linux provides search paths for the linker, and you give those with that -rpath flag I mentioned in the last post. There's no analog on OS X.
Applications, frameworks, and other goodies in OS X are actually directories called bundles - it's essentially just a generic term for gathering together various bits and pieces and presenting them as one entity to the user or developer. (In the Finder, ctrl-click or right-click on any application file and select Show Package Contents to see what's inside a .app bundle.) Buried in an application bundle can be frameworks. So obviously, since you can move an application around, *something* *somewhere* can handle frameworks (and therefore dynamic libraries) moving around as well.
Turns out there's a prefix for the linker that you can use: @executable_path/ Use that in the link phase, and it ties the framework to a relative path to the executable, not an absolute path. As long as the executable and library don't change relative position, you're good.
As it so happens, the project I'm porting has a very strict structure for its build system, and this structure has to be maintained during run time as well... which means that I can treat the whole bloody project directory as an application bundle, more or less, and use @executable_path/ to direct the loader to the proper spot.
Nice.
(no subject)
Date: 2007-10-05 09:55 pm (UTC)I actually understood everything you just said. I feel dirty now.
(no subject)
Date: 2007-10-06 12:03 am (UTC)And yes, you're a dirty, dirty geek.