在macos上安装ruby2.6.7时出错-如何解决?
尝试将 Ruby 升级到 2.6.7 时出现以下错误:
$ rbenv install 2.6.7
...
implicit declaration of function 'rb_native_mutex_destroy' is invalid in C99
vm.c:2489:34: warning: expression does not compute the number of elements in this array; element type is 'const int', not 'VALUE' (aka 'unsigned long') [-Wsizeof-array-div]
sizeof(ec->machine.regs) / sizeof(VALUE));
~~~~~~~~~~~~~~~~ ^
vm.c:2489:34: note: place parentheses around the 'sizeof(VALUE)' expression to silence this warning
有解决办法吗?
回答
是的,这是上游的一个已知问题:https : //bugs.ruby-lang.org/issues/17777
ruby-build 也在跟踪这个问题:https : //github.com/rbenv/ruby-build/issues/1489
解决方法是运行以下代码,然后再次安装 ruby 2.6.7:
$ export warnflags=-Wno-error=implicit-function-declaration
$ rbenv install 2.6.7
-or-
$ CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.7
看起来这也会影响带有本机扩展的 gem 安装(mysql2就是其中之一):
gem install <GEMNAME> -- --with-cflags="-Wno-error=implicit-function-declaration"