Overriding app's library reference path for the particular library

Hello. (hold for a moment, I'll get to the point) I'm developing addon for Blender and I'm trying to make it work on MacOS m1 too. I'm using hppfcl library for the addon and whenever I'm trying to import it from python I get the error below.

Error: Python: Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/m1/Library/Application Support/Blender/3.6/scripts/addons/blenderbim/libs/site/packages/hppfcl/__init__.py", line 34, in <module>
    from .hppfcl import *

ImportError: dlopen(/Users/m1/Library/Application Support/Blender/3.6/scripts/addons/blenderbim/libs/site/packages/hppfcl/hppfcl.cpython-310-darwin.so, 0x0002): Symbol not found: __ZN5boost6python15instance_holder8allocateEP7_objectmm
  Referenced from: /Users/m1/Library/Application Support/Blender/3.6/scripts/addons/blenderbim/libs/site/packages/hppfcl/hppfcl.cpython-310-darwin.so
  Expected in: /Applications/Blender.app/Contents/Resources/lib/libboost_python310.dylib

The error is caused by the fact that /Applications/Blender.app/Contents/Resources/lib/libboost_python310.dylib is incompatible with hppfcl. I have compatible version in /Users/m1/Library/Application Support/Blender/3.6/scripts/addons/blenderbim/libs/libboost_python310.dylib.

❓Mine question is how to make scripts/addons/blenderbim/libs/libboost_python310.dylib either main library to be loaded for hppfcl or for the entire Blender (this will work too)?


What I've tried and researched:

  1. If I check hppfcl library with otool -l hppfcl.cpython-310-darwin.so it's referring to the correct library that should be compatible given that /scripts/addons/blenderbim/libs/site/packages/hppfcl/../../../libboost_python310.dylib => /scripts/addons/blenderbim/libs/libboost_python310.dylib.
Load command 20
          cmd LC_RPATH
      cmdsize 40
         path @loader_path/../../../ (offset 12)
  1. If i run otool -l /Applications/Blender.app/Contents/MacOS/Blender I see why error is referring to /Resources/lib/libboost_python310.dylib. So it seems that hppfcl @loader_path is overriden by Blender's @loader_path.
Load command 65
          cmd LC_RPATH
      cmdsize 48
         path @loader_path/../Resources/lib (offset 12)
  1. I tried to use export DYLD_LIBRARY_PATH="/Users/m1/Library/Application Support/Blender/3.6/scripts/addons/blenderbim/libs/:$DYLD_LIBRARY_PATH" (and same thing with DYLD_FALLBACK_LIBRARY_PATH) before starting Blender which lead to no success - DYLD_LIBRARY_PATH is purged when I start Blender (deduced it by checking os.environ from python). I guess it's because Blender is protected process and the only way around it so either rebuild with different build settings or to disable system integrity protection (both are very bad options for the addon).
Post not yet marked as solved Up vote post of Andrej730 Down vote post of Andrej730
425 views

Replies

It's seems there is no option to ping someone on this forum.

If possible I'd like to summon @eskimo for help

So it seems that hppfcl @loader_path is overriden by Blender’s @loader_path.

That’s not how this is supposed to work. Quoting the dyld man page:

This variable is replaced with the path to the directory containing the mach-o binary which contains the load command using @loader_path. Thus, in every binary, @loader_path resolves to a different path, whereas @executable_path always resolves to the same path.

It then goes on to say:

@loader_path is useful as the load path for a framework/dylib embedded in a plug-in, if the final file system location of the plugin-in unknown (so absolute paths cannot be used) or if the plug-in is used by multiple applications (so @executable_path cannot be used).

which is exactly the case you’re trying to solve.

Unfortunately I don’t have a good explanation for why this is not working. My general advice is:

  • Make sure that all the LC_ID_DYLIB and LC_LOAD_DYLIB commands use simple rpath-relative references, so @rpath/libname.

  • Add an LC_RPATH to your plug-in’s main executable with an @loader_path relative value.

If you get stuck, deploy DYLD_PRINT_SEARCHING. Of course if the plug-in host has the hardened runtime enabled, and hence DYLD_LIBRARY_PATH doesn’t work, DYLD_PRINT_SEARCHING probably won’t work either. You should be able to disable the hardened runtime by re-signing the host app. And if all else fails you can temporarily disable SIP.

It’s seems there is no option to ping someone on this forum.

Indeed. Keep in mind that this isn’t a formal support channel. See tip 3 in Quinn’s Top Ten DevForums Tips. If you want formal support, open a DTS tech support incident. While will be handlede by one of my colleagues because I’m out of the office all week!

Share and Enjoy

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