pythonlinuxshared-librariesapple-m1rosetta

not a mach-o file error in Python - mismatching architecture


For a project, I'm reading a .so file with the ctypes.CDLL and ctypes.cdll.LoadLibrary(...), this is done in a devcontainer. The docker image is based off the following:

FROM --platform=linux/amd64 mcr.microsoft.com/vscode/devcontainers/python:3.10.

Notice the linux/amd64 platform. When checking system information with uname, it shows the x86_64 architecture: Linux ceb596f614b7 5.10.124-linuxkit #1 SMP PREEMPT Thu Jun 30 08:18:26 UTC 2022 x86_64 GNU/Linux. This runs fine, and loads the library without any errors.

However, I have a M1 Mac, where I installed Rosett and Python on that (https://stackoverflow.com/a/71873666/2989034). When I check the system information then, I get the following, also a x86_64 architecture.

Darwin MacBook-van-Bas.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 x86_64

When I load the file in a Rosetta terminal, I get the following error:

OSError: dlopen(/Users/bas/lib.so, 0x0006): tried: '/Users/bas/lib.so' (not a mach-o file)

How is this even possible? It's the same x86_64 architecture. Is my only option working in a devcontainer?


Solution

  • I ended up finding the source code and re-building to a Mach-o file. But to answer my question: Apple platforms draw an important distinction between architecture and platform.