0

Where does ctypes LoadLibrary() search for a shared lib on Mac OS X?

This works:

LoadLibrary("/full/path/to/my_library.dylib")

However,

LoadLibrary("my_library.dylib")

does not work, even /full/path/to) is in PATH and in PYTHONPATH.

1
  • Seems like the solution is the LD_LIBRARY_PATH. Commented Oct 31, 2019 at 15:06

1 Answer 1

2

On OSX (as on (almost) any Nix), CTypes uses dlopen to open an .so (.dylib). According to [Apple.Developer]: DLOPEN(3) (or man dlopen) (emphasis is mine):

When path doesn't contain a slash character (i.e. it is just a leaf name), dlopen() searches the following until it finds a compatible Mach-O file: $LD_LIBRARY_PATH, $DYLD_LIBRARY_PATH, current working directory, $DYLD_FALLBACK_LIBRARY_PATH.

So, you could launch your script like (where %s mark placeholders):

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:%PATH_TO_YOUR_LIB_DIR% %COMMAND_LAUNCHING_SCRIPT% 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.