'mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

I want to use C++ functions in Python program, so I compiled the dynamic library file with the command:

cc -fPIC -shared -o encrypt_for_python.so encrypt_for_python.cpp -L/opt/homebrew/Cellar/[email protected]/1.1.1l/lib -I/opt/homebrew/Cellar/[email protected]/1.1.1l/include -lssl -lcrypto -std=c++11

But when I used it in python file, I got this error:

Traceback (most recent call last):
  File "/Users/debris/Documents/Job/HA/encryption-cpp/test_encrypt.py", line 6, in <module>
    my_func = CDLL(so_file)
  File "/Users/debris/miniconda3/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/debris/Documents/Job/HA/encryption-cpp/encrypt_for_python.so, 0x0006): tried: '/Users/debris/Documents/Job/HA/encryption-cpp/encrypt_for_python.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/encrypt_for_python.so' (no such file), '/usr/lib/encrypt_for_python.so' (no such file)

I found mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'), how can I fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source