【问题标题】:Install Ruby 2.2 on Mac OSX Catalina with ruby-install使用 ruby​​-install 在 Mac OSX Catalina 上安装 Ruby 2.2
【发布时间】:2021-01-03 15:55:54
【问题描述】:

这是我尝试安装 Ruby 2.2 时得到的结果:

$ ruby-install ruby 2.2.10
# ...
>>> Compiling ruby 2.2.10 ...
    CC = clang
    LD = ld
    LDSHARED = clang -dynamic -bundle
    CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens   -pipe
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
    CPPFLAGS = -I/opt/X11/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/gdbm/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -I. -I.ext/include/x86_64-darwin19 -I./include -I.
    DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/gdbm/lib  -fstack-protector -Wl,-u,_objc_msgSend -Wl,-pie -framework CoreFoundation
    SOLIBS = -lgmp
Apple clang version 12.0.0 (clang-1200.0.31.1)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
translating probes probes.d
. ./vm_opts.h
file2lastrev.rb: does not seem to be under a vcs: .
make: [.revision.time] Error 1 (ignored)
./revision.h unchanged
compiling main.c
compiling dmydln.c
compiling miniinit.c
compiling miniprelude.c
compiling array.c
compiling bignum.c
compiling class.c
compiling compar.c
compiling complex.c
compiling dir.c
compiling dln_find.c
compiling encoding.c
encoding.c:825:2: error: implicit declaration of function 'rb_str_change_terminator_length' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        rb_str_change_terminator_length(obj, oldtermlen, termlen);
        ^
1 error generated.
make: *** [encoding.o] Error 1
!!! Compiling ruby 2.2.10 failed!
  • 操作系统版本:10.15.6
  • ruby 安装版本:0.7.1

关于如何调试或修复此问题的任何想法?在升级操作系统之前,我以前能够安装其他版本的 2.2。我还可以毫无问题地安装 Ruby 2.7 等更高版本

【问题讨论】:

  • 有同样的问题。我有 ruby​​ 2.2.4 和 MacOS 10.15.5。我正在运行rvm pkg install openssl
  • 实际运行中-rvm reinstall 2.2.10 --with-openssl-dir=$HOME/.rvm/usr
  • 如果你想绕过 Travis CI 的问题 a list of ruby binaries,包括 2.2.4。

标签: ruby macos installation compilation


【解决方案1】:

经过一番折腾并意识到错误与使用 macOS 原生的 GCC 进行编译有关后,我决定进行测试。

因为旧版本的 Ruby 需要更新的 make 中不再存在的指令,所以有必要下载旧版本的 Xcode 命令行工具。

首先,删除您的实际版本:

sudo rm -rf /Library/Developer/CommandLineTools

忽略缺少 git 的错误。

前往https://developer.apple.com/download/more/ 并下载适用于 Xcode 的 11.x 版命令行工具。

我下载了 11.5 版,它工作正常。 我跑的时候回来gcc -v

Configured with: --prefix = / Library / Developer / CommandLineTools / usr --with-gxx-include-dir = / Library / Developer / CommandLineTools / SDKs / MacOSX.sdk / usr / include / c ++ / 4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: / Library / Developer / CommandLineTools / usr / bin

与最近的命令行 12.x 进行比较,您会看到如下内容:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

【讨论】:

  • 安装 11.x 版本的命令行工具并没有为我解决这个问题。 gcc -v 仍然显示 12.x 版本的输出。然而,下载并安装 full Xcode 11.5 包确实解决了这个问题。非常感谢您为我指明了这个方向!
  • 很奇怪。但是我没有安装完整的 Xcode。我会更新我的答案。
【解决方案2】:

显然忽略编译器警告也是一种选择

export optflags="-Wno-error=implicit-function-declaration"

更多讨论见Problem when installing Ruby 2.2.9 on Mac Big Sur M1

【讨论】:

  • 这对我有用 rbenv/ruby-build,谢谢。
  • 不幸的是,当我尝试使用 ruby​​-install 安装 Ruby 3.0.3 时,这 not 对我有用:它确实绕过了大部分错误,但后来 C代码尝试引用由隐式声明的函数之一返回的结构指针,并且由于函数的返回类型已被隐式假定为 int……是的,那是行不通的。 :(
【解决方案3】:

我能够使用 rvm 在 Mac 10.15.7 上安装该版本。

我已经用自制软件安装了 openssl@1.1。如果您运行brew info openssl,您会看到什么?我会先试试brew upgrade openssl

尝试运行 export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" 与信息 brew 返回。然后尝试rvm install 2.2.10。如果这不起作用,我会尝试rvm install 2.2.10 --with-openssl-dir=/usr/local/opt/openssl --with-openssl-lib=/usr/local/opt/openssl/lib --with-openssl-include=/usr/local/opt/openssl/include,只要确保这些路径对您的系统正确。

您可能还需要运行

export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"

export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

事先,将由brew info提供。

【讨论】:

  • 设置 PKG_CONFIG_PATH 对我有用。具有讽刺意味的是,它似乎奏效了,因为我的 OpenSSL 版本 (3.0.1) 太新了,所以 Ruby 构建只是跳过了完全安装 openssl 扩展的尝试,说:“OpenSSL >= 1.0.1, = 2.5.0 是必需的。”但无论如何,至少我现在有一个(大部分)工作的 Ruby。 :D
【解决方案4】:

在此处添加一些可能有帮助的额外选项:

我们需要正确的 SSL 版本:

$ brew install rbenv/tap/openssl@1.0

$ rvm install 2.2.10 -C --with-openssl-dir=`brew --prefix openssl@1.0`

【讨论】:

    【解决方案5】:

    首先,安装open-ssl

    brew install rbenv/tap/openssl@1.0
    

    然后

    CFLAGS="-Wno-error=implicit-function-declaration" rvm reinstall ruby-2.2.5 --with-openssl-dir='/usr/local/opt/openssl@1.0'
    

    【讨论】:

      【解决方案6】:

      我最近不得不在 Catalina 10.15.7 中安装 ruby​​-2.2.0 并且遇到了同样的问题。但幸运的是成功地完成了我的工作。步骤如下:

      1. 将 openssl 安装为 rvm 包:

        $ rvm pkg install openssl
      2. 忽略编译器警告:

        $ export optflags="-Wno-error=implicit-function-declaration"
      3. 安装所需的 ruby​​ 版本(在我的情况下为 2.2.0),同时提供 openssl 目录参数并忽略 ruby​​gems:

        $ rvm install 2.2.0 --with-openssl-dir=$rvm_path/usr --rubygems 忽略

      【讨论】:

        猜你喜欢
        • 2020-08-12
        • 1970-01-01
        • 1970-01-01
        • 2021-01-12
        • 1970-01-01
        • 1970-01-01
        • 2014-04-24
        • 1970-01-01
        相关资源
        最近更新 更多