为 arm64 iOS 模拟器构建 openssl

时间:2021-06-22 16:08:12

标签: ios xcode openssl

说明

我正在尝试使用架构 arm64 构建仅限 iphonesimulator 的目标库,但链接步骤因错误而失败:

${LDCMD:-/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang}  -O3 -fvisibility=hidden -miphoneos-version-min=9.0 -fembed-bitcode -fPIC -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk -L. -Wl,-search_paths_first  \
                -o apps/openssl apps/asn1pars.o apps/ca.o apps/ciphers.o apps/cms.o apps/crl.o apps/crl2p7.o apps/dgst.o apps/dhparam.o apps/dsa.o apps/dsaparam.o apps/ec.o apps/ecparam.o apps/enc.o apps/errstr.o apps/gendsa.o apps/genpkey.o apps/genrsa.o apps/nseq.o apps/ocsp.o apps/openssl.o apps/passwd.o apps/pkcs12.o apps/pkcs7.o apps/pkcs8.o apps/pkey.o apps/pkeyparam.o apps/pkeyutl.o apps/prime.o apps/rand.o apps/rehash.o apps/req.o apps/rsa.o apps/rsautl.o apps/s_client.o apps/s_server.o apps/s_time.o apps/sess_id.o apps/smime.o apps/speed.o apps/spkac.o apps/srp.o apps/storeutl.o apps/ts.o apps/verify.o apps/version.o apps/x509.o \
                 apps/libapps.a -lssl -lcrypto  
ld: building for iOS, but linking in .tbd file (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/lib/libSystem.tbd) built for iOS Simulator, file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/lib/libSystem.tbd' for architecture arm64

配置命令:

./Configure iossimulator-xcrun threads no-shared "-fvisibility=hidden -miphoneos-version-min=9.0 -fembed-bitcode -fPIC" no-asm no-hw no-async --prefix=/Users/macosuser/Build/OpenSSL/Install "-arch arm64" "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk"
Configuring OpenSSL version 1.1.1j (0x101010afL) for iossimulator-xcrun
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

构建命令如下所示:

...
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -I. -Iinclude -Iapps  -O3 -fvisibility=hidden -miphoneos-version-min=9.0 -fembed-bitcode -fPIC -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk -D_REENTRANT -DNDEBUG  -MMD -MF apps/x509.d.tmp -MT apps/x509.o -c -o apps/x509.o apps/x509.c
...

问题

我不明白为什么其他架构(i386x86_64)的构建没有问题。 也许我遗漏了一些细微差别,但我无法理解是哪一个。

为什么我需要这个 - 使用这个库的应用程序必须在带有 M1 处理器的 macbook 中的模拟器上运行。

环境规范

  • MacOS 11.4
  • XCode v12.5
  • OpenSSL v1.1.1j
  • 编译器 - AppleClang 12.0.5.12050022

1 个答案:

答案 0 :(得分:0)

因为我不是 iOS 开发人员,所以我没有立即了解通过 make 为这个平台构建库的细节。

问题是这样的:

-miphoneos-version-min 指定了 iOS 的部署目标,但由于我正在为 iOS 模拟器构建库,我需要使用 -mios-simulator-version-min

因此,配置命令应如下所示:

./Configure iossimulator-xcrun threads no-shared "-fvisibility=hidden -mios-simulator-version-min=9.0 -fembed-bitcode -fPIC" no-asm no-hw no-async --prefix=/Users/macosuser/Build/OpenSSL/Install "-arch arm64" "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk"

如果有人能解释为什么 -miphoneos-version-min 标志可以在 i386 和 x86_64 架构上按预期工作,我将不胜感激。