0

I have a big library of C++ code that I have already wrapped in python on Ubuntu, dividing the wrap in different modules and everything works. The problems start when I want to do the same operation on MacOS (M1). First of all, I tried to get swig to produce .dylib libraries instead of the regular .so ones, that I thought are not working with Mac.

Then, I set on my .zshrc file the following variables:

export PYTHONPATH="/Users/myname/Library/FolderOfTheDYLIB"
export DYLD_FALLBACK_LIBRARY_PATH="/Users/myname/Library/FolderOfTheDYLIB"

but when I try to include the python library I get the following error:

ModuleNotFoundError: No module named '_myModule1'

Basically, there is no way to let python find my modules. So, I tried to produce the regular .so libraries instead of the .dylib ones. When I do that, I get this different error:

ImportError: dlopen(/Users/myname/Library/FolderOfTheDYLIB/_myModule1.so, 0x0002): symbol not found in flat namespace (___aarch64_cas8_relax)

That seems to me a compatibility problem with the arch64 architecture.

What can I do?

  • This has nothing to do with SWIG, this is a Python build problem. Check this: https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx What Python build system are using? Homegrown? Your error is about a missing compiler intrinsic which is usually caused by selecting a wrong target architecture. – mmomtchev Jul 05 '23 at 20:10
  • Ok thank you. So, I understand that is not necessary to build .dylib libraries. I made .so ones, passing to the compiler the flags: -dynamiclib -undefined dynamic_lookup. The `ImportError: dlopen(/Users/myname/Library/FolderOfTheDYLIB/_myModule1.so, 0x0002): symbol not found in flat namespace (___aarch64_cas8_relax)` is still present and I have no idea how to solve it... Yes, I have a homegrown Python build system, I try to add to the flags -target arm64-apple-macos12 but nothing changed – Simone Sartori Jul 05 '23 at 21:39
  • Try using the same compiler/version as the python interpreter - where is the python coming from? – mmomtchev Jul 08 '23 at 09:58

0 Answers0