Repository navigation
ctypes.util.find_library raises FileNotFoundError for libsecp256k1 #93094
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 23, 2022 When I do a
print(trace)just before
Line 139 in 8241a69
res = re.findall(expr, trace)
I getb'/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o\n/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crti.o\n/usr/lib/gcc/x86_64-linux-gnu/11/crtbeginS.o\n/usr/bin/ld: cannot find -llibsecp256k1: No such file or directory\n/usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libsecp256k1.a use -l:libsecp256k1.a or rename it to liblibsecp256k1.a\n/usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a\n/usr/lib/gcc/x86_64-linux-gnu/11/libgcc_s.so\n/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgcc_s.so.1\n/usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a\ncollect2: error: ld returned 1 exit status\n'here with replaced
\nb'/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/11/crtbeginS.o /usr/bin/ld: cannot find -llibsecp256k1: No such file or directory /usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libsecp256k1.a use -l:libsecp256k1.a or rename it to liblibsecp256k1.a /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a /usr/lib/gcc/x86_64-linux-gnu/11/libgcc_s.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgcc_s.so.1 /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a collect2: error: ld returned 1 exit status 'My interpretation of this is, that the
relogic inis not sufficient to handle theLine 139 in 8241a69
res = re.findall(expr, trace) ldmessage.I face the same issue, when the output is polluted with message from ld, in my case:
/usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libusb-1.0.a use -l:libusb-1.0.a or rename it
reproduced with using pyInstaller package, but can be reproduced easily, see below.Environment:
Ubuntu 22.04 LTS
uname: Linux ubu22-virtual 5.15.0-50-generic #56-Ubuntu SMP Tue Sep 20 13:23:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Python: 3.10.6Steps to reproduce:
sudo apt install libusb-1.0-0-dev /usr/bin/gcc -Wl,-t -o /tmp/tmpp455oz01 -llibusb-1.0outputting
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/11/crtbeginS.o /usr/bin/ld: cannot find -llibusb-1.0: No such file or directory /usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libusb-1.0.a use -l:libusb-1.0.a or rename it to liblibusb-1.0.a /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a /usr/lib/gcc/x86_64-linux-gnu/11/libgcc_s.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgcc_s.so.1 /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a collect2: error: ld returned 1 exit statusin python3
from ctypes import util util.find_library('libusb-1.0') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.10/ctypes/util.py", line 341, in find_library _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name)) File "/usr/lib/python3.10/ctypes/util.py", line 147, in _findLib_gcc if not _is_elf(file): File "/usr/lib/python3.10/ctypes/util.py", line 99, in _is_elf with open(filename, 'br') as thefile: FileNotFoundError: [Errno 2] No such file or directory: b'liblibusb-1.0.a'If the gcc produces only the list of files, then prepending
^as looking for whole line could fix the issue.
expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
to
expr = os.fsencode(r'^[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))I'm proposing to soft-deprecate
ctypes.util.find_library: https://discuss.python.org/t/106232It is now soft-deprecated. It cannot be made to work correctly and consistently on all platforms, and any change runs a chance to break whatever workarounds people already have in place.
I'm prioritizing stability over new features, and encourage solving this outside ctypes itself.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Bug report
The following script
gives the output:
find_libraryshould not fail, but returnNoneif nothing was found. In Ubuntu 20.04 this script runs without any exception.Your environment
libsecp256k1packages areAnd
contains the files
And in

/usr/lib/x86_64-linux-gnu/are the following relevant files containingsecp256k1:This bug was noticed in cryptoadvance/specter-desktop#1710