2

I'm using a Mac M1 with arm64 chip and I have an executable that depends on different .dylibs located in /usr/lib. These are: libc++.1.dylib, libSystem.b.dylib and libobjc.A.dylib.

I got these results by doing otool -L myExecutable. Since I'm trying to distribute this application, I'm trying to gather all the dependencies in one place, so I went to /usr/lib to look for the libraries but none of them were there.

Why are they not there? Why does my application run correctly without the .dylibs in the correct place? Are they actually needed to run? And where are they located if they exist in my computer at all?

1 Answers1

0

Apple removed the libraries from the directories listed. In other words, ls can't see them.

However, the libraries are still there. You must use dlopen to access them. Apple did this so that it could automatically port libraries needed to different CPU architecture. That porting is expensive -- so dlopen first checks in a dylib cache for the libraries.

This cache is the reason why the libraries are gone.

You can verify that the libraries still exist via dlopen:

from cffi import FFI
ffi = FFI()
ffi.dlopen('/usr/lib/libSystem.B.dylib')
ffi.dlopen('/usr/lib/actually-nonexistent-library')

This shows the following results:

<cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7fc1b83d1210>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/cade/opt/anaconda3/envs/my-env/lib/python3.7/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/cade/opt/anaconda3/envs/my-env/lib/python3.7/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/Users/cade/opt/anaconda3/envs/my-env/lib/python3.7/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library '/usr/lib/actually-nonexistent-library': dlopen(/usr/lib/actually-nonexistent-library, 0x0002): tried: '/usr/lib/actually-nonexistent-library' (no such file), '/usr/local/lib/actually-nonexistent-library' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/usr/lib/actually-nonexistent-library'
cade
  • 563
  • 4
  • 15