Reputation: 111
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?
Upvotes: 4
Views: 8982
Reputation: 111
I found this:
file ~/miniconda3/bin/python
/Users/debris/miniconda3/bin/python: Mach-O 64-bit executable x86_64
By installing python for amd64, I solved this problem.@Alan Birtles Thank you very much.
Upvotes: 3