If you are using weak linking for your dylib, it should be pretty easy to detect if the library is present by checking for a particular symbol.
Say you have a void foo( void );
function in that library.
You can declare that prototype as extern
in your own code, and use the weak_import
attribute:
extern void foo( void ) __attribute__( ( weak_import ) );
This way, if the symbol is not found (because its not anymore in the library, or because the whole library is not available), the linker will set the address of the symbol to NULL
.
You can then simply and elegantly check for that symbol:
if( foo == NULL )
{
/* Alerts the user */
}
else
{
/* It's safe to use foo() */
}
For further reading: Framework Programming Guide