在MacOS Sonoma上交叉编译Python cryptography到Android遇错求助
在macOS Sonoma上为Android交叉编译pyca/cryptography库的问题
我正在macOS Sonoma系统上尝试为Android平台交叉编译pyca/cryptography库,试过各种配置组合,但每次都会遇到不同错误,其他库的交叉编译都没问题。
有没有人能提供一个包含必要修改的可运行示例?
最近一次尝试出现以下错误:
ld: error: unable to find library -lpthread error: command '/Users/tobiaslindell/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang' failed with exit code 1
错误发生前buildozer/p4a的日志如下:
[DEBUG]: creating build/lib.macosx-14.4-arm64-cpython-311/cryptography/hazmat/bindings [DEBUG]: /Users/tobiaslindell/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -target aarch64-linux-android21 -fomit-frame-pointer -march=armv8-a -fPIC -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -L/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/libs_collections/convokeeper/arm64-v8a -L/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/android-build -lpython3.11 -L/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/other_builds/openssl/arm64-v8a__ndk_target_21/openssl1.1 -target aarch64-linux-android21 -fomit-frame-pointer -march=armv8-a -fPIC -I/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/other_builds/python3/arm64-v8a__ndk_target_21/python3/Include -I/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/other_builds/openssl/arm64-v8a__ndk_target_21/openssl1.1/include -I/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/other_builds/openssl/arm64-v8a__ndk_target_21/openssl1.1/include/internal -I/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/other_builds/openssl/arm64-v8a__ndk_target_21/openssl1.1/include/openssl -DANDROID -I/Users/tobiaslindell/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include -I/Users/tobiaslindell/appStuff/.buildozer/android/platform/build-arm64-v8a/build/python-installs/convokeeper/arm64-v8a/include/python3.1 build/temp.macosx-14.4-arm64-cpython-311/build/temp.macosx-14.4-arm64-cpython-311/cryptography.hazmat.bindings._openssl.o -lssl -lcrypto -lpthread -o build/lib.macosx-14.4-arm64-cpython-311/cryptography/hazmat/bindings/_openssl.abi3.so [DEBUG]: ld: error: unable to find library -lpthread
我修改了下面文件的最后一行(移除了"pthread")来绕过这个错误,但觉得这不是正确的解决办法:
# This file is dual licensed under the terms of the Apache License, Version # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. import os import sys from distutils import dist from distutils.ccompiler import get_default_compiler from distutils.command.config import config from _cffi_src.utils import build_ffi_for_binding, compiler_type def _get_openssl_libraries(platform): if os.environ.get("CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS", None): return [] # OpenSSL goes by a different library name on different operating systems. if platform == "win32" and compiler_type() == "msvc": return [ "libssl", "libcrypto", "advapi32", "crypt32", "gdi32", "user32", "ws2_32", ] else: # darwin, linux, mingw all use this path # In some circumstances, the order in which these libs are # specified on the linker command-line is significant; # libssl must come before libcrypto # (https://marc.info/?l=openssl-users&m=135361825921871) # -lpthread required due to usage of pthread an potential # existance of a static part containing e.g. pthread_atfork # (https://github.com/pyca/cryptography/issues/5084) if sys.platform == "zos": return ["ssl", "crypto"] else: return ["ssl", "crypto", "pthread"]
我的环境配置如下:
Python: 3.11.5 host: arm64 (macOS Sonoma 14.4.1) target: arm64-v8a (Android) pip: 25.0 setuptools: 75.8.0 setuptools_rust: 1.10.2 rustc: 1.84.0 (9fc6b4312 2025-01-07) appdirs 1.4.4 build 1.2.2.post1 buildozer 1.5.0 certifi 2025.1.31 cffi 1.15.1 charset-normalizer 3.4.1 colorama 0.4.6 cryptography 38.0.1 Cython 0.29.33 Deprecated 1.2.16 distlib 0.3.9 docutils 0.21.2 filelock 3.17.0 filetype 1.2.0 gcloud 0.18.3 googleapis-common-protos 1.66.0 httplib2 0.22.0 idna 3.10 Jinja2 3.1.5 jwcrypto 1.4.2 Kivy 2.3.1 Kivy-Garden 0.1.5 MarkupSafe 3.0.2 oauth2client 4.1.3 packaging 24.2 pexpect 4.9.0 pip 24.3.1 platformdirs 4.3.6 protobuf 5.29.3 ptyprocess 0.7.0 pyasn1 0.6.1 pyasn1_modules 0.4.1 pycparser 2.22 pycryptodome 3.21.0 Pygments 2.19.1 pyparsing 3.2.1 pyproject_hooks 1.2.0 Pyrebase4 4.8.0 python-jwt 4.1.0 requests 2.32.3 requests-toolbelt 0.10.1 rsa 4.9 semantic-version 2.10.0 setuptools 75.8.0 setuptools-rust 1.10.2 sh 1.14.3 six 1.17.0 toml 0.10.2 urllib3 1.26.20 virtualenv 20.29.1 wheel 0.45.1 wrapt 1.17.2 # Homebrew path export PATH="/opt/homebrew/bin:$PATH" # Paths used for locating shared libraries and package configurations export LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib -L/usr/local/openssl-1.1/lib -L$(brew --prefix libffi)/lib -L/opt/homebrew/opt/binutils/lib -L/usr/local/opt/expat/lib" export CPPFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix bzip2)/include -I/usr/local/openssl-1.1/include -I$(brew --prefix libffi)/include -I/opt/homebrew/opt/binutils/include -I/usr/local/opt/expat/include" export PKG_CONFIG_PATH="/usr/local/openssl-1.1/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix bzip2)/lib/pkgconfig:$(brew --prefix libffi)/lib/pkgconfig:/opt/homebrew/opt/expat/lib/pkgconfig" export SSL_CERT_FILE=$(python3 -m certifi) # Pipenv language flag export LANG=en_US.UTF-8 # Cargo path export PATH="$HOME/.cargo/bin:$PATH" # Perl path eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)" # Java path export JAVA_HOME=/usr/local/jdk-17/jdk-17.0.14.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATH # OpenSSL path export OPENSSL_HOME=/usr/local/openssl-1.1 export PATH=$OPENSSL_HOME/bin:$PATH
内容的提问来源于stack exchange,提问作者Tobias Lindell
相关产品推荐
相关产品推荐

