I have a binary, advertised as working on Mac OS X 10.6, but that tries to link wcsdup()
, a function that was only added in 10.7. This is an extract from the bug report generated when launching on 10.6.8:
Process: paradiseperfectboatrescue [149] … Code Type: X86-64 (Native) Parent Process: launchd [86] … OS Version: Mac OS X 10.6.8 (10K549) … Dyld Error Message: Symbol not found: _wcsdup Referenced from: …/Paradise Perfect Boat Rescue.app/Contents/MacOS/paradiseperfectboatrescue Expected in: /usr/lib/libSystem.B.dylib …
The developer, for one reason or another, has not fixed the issue, reported ~6 months ago. I was wondering if there was any hope of circumventing the problem with programmatic tools. Specifically, would it be possible to instruct dyld to get wcsdup()
from elsewhere? It is a simple function and assuming it is the only function missing, it can be implemented easily. Here is the implementation I would use, given the chance:
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
wchar_t* wcsdup (const wchar_t *s)
{
size_t len = wcslen(s) + 1;
len *= sizeof(wchar_t);
wchar_t *d = malloc(len);
if (d)
return memcpy(d, s, len);
else
return 0;
}
I have used DYLD_LIBRARY_PATH
in other circumstances, but then I wanted to help dyld to find entire libraries that it otherwise missed. This time my goal is not to provide an entire new library but to supplement the existing one with a few functions that use functions from the library being supplemented. Is it possible to tell dyld to do this?
I think you want DYLD_INSERT_LIBRARIES
, see here: http://tlrobinson.net/blog/2007/12/overriding-library-functions-in-mac-os-x-the-easy-way-dyld_insert_libraries/
This is like LD_PRELOAD
on Linux...rather than giving a list of library paths to inspect for libraries an executable knows it needs, we load functions from a specific file and prevent searching for them elsewhere.