使用 OS X Mojave 安装旧 scrypt gem 版本时出现 i386 arch 错误

i386 arch error installing old scrypt gem version with OS X Mojave

我正在尝试在全新安装 OS X 10.14 Mojave 和 XCode 命令行工具后为旧项目安装旧 gem 版本。 gem 我正在尝试安装的是 scrypt,版本 1.2.1,它是 authlogic 的依赖项。

gem 安装 scrypt -v=1.2.1

Returns 出现如下错误:

Building native extensions. This could take a while...
ERROR:  Error installing scrypt:
    ERROR: Failed to build gem native extension.

    current directory: /Users/chris/.rvm/gems/ruby-2.4.4@rails5/gems/scrypt-1.2.1/ext/scrypt
/Users/chris/.rvm/rubies/ruby-2.4.4/bin/ruby -rrubygems /Users/chris/.rvm/gems/ruby-2.4.4@global/gems/rake-12.0.0/exe/rake RUBYARCHDIR=/Users/chris/.rvm/gems/ruby-2.4.4@rails5/extensions/x86_64-darwin-18/2.4.0/scrypt-1.2.1 RUBYLIBDIR=/Users/chris/.rvm/gems/ruby-2.4.4@rails5/extensions/x86_64-darwin-18/2.4.0/scrypt-1.2.1
mkdir -p x86_64-darwin
gcc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -arch x86_64 -arch i386   -o x86_64-darwin/crypto_scrypt-sse.o -c ./crypto_scrypt-sse.c
gcc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -arch x86_64 -arch i386   -o x86_64-darwin/memlimit.o -c ./memlimit.c
gcc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -arch x86_64 -arch i386   -o x86_64-darwin/scrypt_calibrate.o -c ./scrypt_calibrate.c
gcc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -arch x86_64 -arch i386   -o x86_64-darwin/scrypt_ext.o -c ./scrypt_ext.c
gcc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -arch x86_64 -arch i386   -o x86_64-darwin/scryptenc_cpuperf.o -c ./scryptenc_cpuperf.c
gcc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -arch x86_64 -arch i386   -o x86_64-darwin/sha256.o -c ./sha256.c
gcc -bundle -o x86_64-darwin/libscrypt_ext.bundle x86_64-darwin/crypto_scrypt-sse.o x86_64-darwin/memlimit.o x86_64-darwin/scrypt_calibrate.o x86_64-darwin/scrypt_ext.o x86_64-darwin/scryptenc_cpuperf.o x86_64-darwin/sha256.o -fexceptions -arch x86_64 -arch i386 
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture i386:
  "___error", referenced from:
      _crypto_scrypt in crypto_scrypt-sse.o
      _memtouse in memlimit.o
  "___stack_chk_fail", referenced from:
      _scrypt_SHA256_Transform in sha256.o
      _scrypt_SHA256_Final in sha256.o
      _HMAC_scrypt_SHA256_Init in sha256.o
      _HMAC_scrypt_SHA256_Final in sha256.o
      _PBKDF2_scrypt_SHA256 in sha256.o
  "___stack_chk_guard", referenced from:
      _scrypt_SHA256_Transform in sha256.o
      _scrypt_SHA256_Final in sha256.o
      _HMAC_scrypt_SHA256_Init in sha256.o
      _HMAC_scrypt_SHA256_Final in sha256.o
      _PBKDF2_scrypt_SHA256 in sha256.o
  "_free", referenced from:
      _crypto_scrypt in crypto_scrypt-sse.o
  "_getrlimit$UNIX2003", referenced from:
      _memtouse in memlimit.o
  "_gettimeofday", referenced from:
      _scryptenc_cpuperf in scryptenc_cpuperf.o
  "_malloc", referenced from:
      _crypto_scrypt in crypto_scrypt-sse.o
  "_memcpy", referenced from:
      _scrypt_SHA256_Update in sha256.o
      _PBKDF2_scrypt_SHA256 in sha256.o
  "_mmap$UNIX2003", referenced from:
      _crypto_scrypt in crypto_scrypt-sse.o
  "_munmap$UNIX2003", referenced from:
      _crypto_scrypt in crypto_scrypt-sse.o
  "_sysconf", referenced from:
      _memtouse in memlimit.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
rake aborted!
Command failed with status (1): [gcc -bundle -o x86_64-darwin/libscrypt_ext...]
/Users/chris/.rvm/gems/ruby-2.4.4@rails5/gems/ffi-compiler-1.0.1/lib/ffi-compiler/compile_task.rb:153:in `block in define_task!'
/Users/chris/.rvm/gems/ruby-2.4.4@global/gems/rake-12.0.0/exe/rake:27:in `<main>'
Tasks: TOP => default => x86_64-darwin/libscrypt_ext.bundle
(See full trace by running task with --trace)

rake failed, exit code 1

最新版本的 macOS 似乎已弃用并删除了 i386 架构。假设您无法升级 scrypt 版本(这可能是最佳选择)

,至少还有 2 个选项可能适合您
  • 使用 docker 图片。我刚用 ruby:2.5.3-slim 测试过,你只需要 运行 apt-get update && apt-get build-essential && gem install scrypt -v 1.2.1
  • 下载包含 i386 架构的旧版 SDK,并将其安装到您的系统上。 This 有一些可能有用的链接和信息(尽管不是 rails 特定的)

安装 command line tools for 10.13 为我解决了这个问题。

我确实遇到了这个问题。

我是 运行 Mojave (10.14.4) 和 XCode 命令行工具的版本 10.2,当 运行 gem install scrypt -v 1.2.1 时,我得到了与上述完全相同的错误。

解决方案是安装此软件包:/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg(如 Can't compile C program on a Mac after upgrade to Mojave). Apparently the root of the issue was that somewhere in this process (bundler? scrypt?) there was an expectation that header files could be found in /usr/include. The latest version of XCode does not place header files in that location, but running the package places them there (as documented in the XCode release notes 中所述)

我尝试了给出的所有版本的答案,它并不完全适合我。然后以下步骤对我有用。

首先检查 header 个文件是否存在。

ls /usr/include
ls: /usr/include: No such file or directory

由于 header 不存在,我删除了 CommandLineTools,就像 this answer

中给出的那样
sudo rm -rf /Library/Developer/CommandLineTools

更新 xcode 并安装 macOS_SDK_headers_for_macOS_10。14.pkg

xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

现在 header 文件在我做的时候出现了 ls /usr/include

gem install scrypt -v 1.2.1