herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
450 stars 152 forks source link

she.py failed to run in Mac OS X 11.2.2 [Intel] #106

Closed eNipu closed 3 years ago

eNipu commented 3 years ago

Tried to run the she.py.

Getting the following error.

Traceback (most recent call last):
  File "she.py", line 271, in <module>
    init(BLS12_381)
  File "she.py", line 37, in init
    lib = cdll.LoadLibrary(libName)
  File "~/.pyenv/versions/3.7.7/lib/python3.7/ctypes/__init__.py", line 442, in LoadLibrary
    return self._dlltype(name)
  File "~/.pyenv/versions/3.7.7/lib/python3.7/ctypes/__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libmclshe384_256.dylib, 6): image not found

Changing the code to find the library solves the above error. lib = cdll.LoadLibrary(find_library(libName))

However, then getting the following error:

Traceback (most recent call last):
  File "she.py", line 272, in <module>
    init(BLS12_381)
  File "she.py", line 39, in init
    ret = lib.sheInit(curveType, MCLBN_COMPILED_TIME_VAR)
  File "~/.pyenv/versions/3.7.7/lib/python3.7/ctypes/__init__.py", line 377, in __getattr__
    func = self.__getitem__(name)
  File "~/.pyenv/versions/3.7.7/lib/python3.7/ctypes/__init__.py", line 382, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, sheInit): symbol not found
herumi commented 3 years ago

Please exec python3 in mcl/lib for the original she.py.

cd lib
python3 ../ffi/python/she.py
eNipu commented 3 years ago

@herumi I followed the instruction. Did not solve the issue. The same error message.

herumi commented 3 years ago

Do you use the original she.py? she.py with find_library showed your error.

% uname -a
Darwin macpro.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
% clang -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

cd mcl/lib
# original she.py
mcl/lib% python3 ../ffi/python/she.py
sec= 1457dedb3b908df3281313805b31177d1d22c548ed9050e9d0d1521c45aa6c45e56ba603147225f3c28d53a1dbeec9b647b6a2abdba13f0b3f69d8b5aae1622b
pub= 668a7d2363569deb6c163aa18e9b8fa384a869e5b8d1caef012b7a7b2d30bdab081d8f3a68926b0cfa2e9e19169c0505ca6a50939d2d237db65e6f605cd527d3dbc0ef85c960d49ebd6ff05ceb155e0de9a33c8153b8d4245413f2780148a900c342e4e1d823eb5ffb0fdd36cefa90e57c0a8b04b9180e5e493903c660ffa5f040062957a6b0061de5f1e9bf4ddf2497
0.08275695479msec
0.0239759394msec

# she.py with find_library

% git di
diff --git a/ffi/python/she.py b/ffi/python/she.py
index 538515f..f9d8372 100644
--- a/ffi/python/she.py
+++ b/ffi/python/she.py
@@ -1,7 +1,7 @@
 import os
 import platform
 from ctypes import *
-#from ctypes.util import find_library
+from ctypes.util import find_library

 BN254 = 0
 BLS12_381 = 5
@@ -35,8 +35,8 @@ def init(curveType=BN254):
                libName = 'mclshe384_256.dll'
        else:
                raise RuntimeError("not support yet", name)
-#  lib = cdll.LoadLibrary(find_library(libName))
-   lib = cdll.LoadLibrary(libName)
+ lib = cdll.LoadLibrary(find_library(libName))
+#    lib = cdll.LoadLibrary(libName)
        ret = lib.sheInit(curveType, MCLBN_COMPILED_TIME_VAR)
        if ret != 0:
                raise RuntimeError("sheInit", ret)
macpro.local:/Users/shigeo/Program/mcl/lib% python3 ../ffi/python/she.py
Traceback (most recent call last):
  File "../ffi/python/she.py", line 273, in <module>
    init(BLS12_381)
  File "../ffi/python/she.py", line 40, in init
    ret = lib.sheInit(curveType, MCLBN_COMPILED_TIME_VAR)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, sheInit): symbol not found
eNipu commented 3 years ago

@herumi The problem is solved. I need to install the library in /usr/local/lib running sudo make install
to solve the problem. Thank you for the detailed reply. Closing the issue