'dlopen' ignore LD_LIBRARY_PATH on macOS 12.2, 12.3

Hi,

'dlopen' ignores the search path that is defined for LD_LIBRARY_PATH on macOS 12.2 and 12.3, even-though the path doesn't contain slash.

LD_LIBRARY_PATH is set as follows (before the call): export LD_LIBRARY_PATH="/Users/administrator/Desktop/Test/"

'test_library.dylib' is located under '/Users/administrator/Desktop/Test/'

The c call at the application looks as follows (The application is built by Xcode 13): handle = dlopen("test_library.dylib", RTLD_LAZY);

I see that the error i get, when calling to dlopen, is that test_library.dylib isn't found. From the error it looks that library loader doesn't search the library at the search path that is defined for LD_LIBRARY_PATH. During the call, the LD_LIBRARY_PATH contains the path.

If i set this path to DYLD_LIBRARY_PATH, dlopen finds 'test_library.dylib' and everything works as expected.

I didn't find any documentation for this issue, therefore, is it a known limitation? Is there a workaround?

Thx, Moshe.

Replies

If i set this path to DYLD_LIBRARY_PATH, dlopen finds test_library.dylib and everything works as expected.

AFAICT dyld3 never supported LD_LIBRARY_PATH and, now that dyld2 and dyld3 are merged into dyld4, that lack of support has come to the Mac. I suspect that this was deliberate but I can’t find any concrete evidence for that.

If you’d like me to confirm this for real, open a DTS tech support incident for this; that’ll allow me time to investigate properly.

Regardless, it’s clear that the dlopen man page could do with an update and I encourage you to file a bug requesting that. Please post your bug number, just for the record.


Regardless of all of the above, relying on dynamic linker search path environment variables is something I recommend against, especially for dlopen where you can use whatever algorithm you want to find libraries and then pass dlopen a full path. So, why are you doing this?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I am aware of the cons of relying on dynamic linker search path environment variable. I am just checking some old code.

I filed a bug - FB10004087

Thx, Moshe.

I filed a bug - FB10004087

Thanks.

I was curious about the death of LD_LIBRARY_PATH so I asked the linker team about this. Its removal was definitely deliberate. The rationale was that it was basically redundant versus DYLD_LIBRARY_PATH, but harder to support due to historical baggage. We removed the discussion of it from the dyld man page but missed it in the dlopen one.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"