安装 bcrypt-ruby gem 时无法构建 gem 本机扩展

Failed to build gem native extension when installing bcrypt-ruby gem

当 运行: gem install bcrypt-ruby -v '3.0.1' 我得到以下错误:

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

    current directory: /U/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bcrypt-ruby-3.0.1/ext/mri
/U/.rbenv/versions/2.7.2/bin/ruby -I /U/.rbenv/versions/2.7.2/lib/ruby/2.7.0 -r ./siteconf20210824-80693-sdyma7.rb extconf.rb
creating Makefile

current directory: /U/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bcrypt-ruby-3.0.1/ext/mri
make "DESTDIR=" clean

current directory: /U/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bcrypt-ruby-3.0.1/ext/mri
make "DESTDIR="
compiling bcrypt_ext.c
bcrypt_ext.c:27:19: error: implicit declaration of function 'ruby_bcrypt' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return (VALUE)ruby_bcrypt(args->output, args->key, args->salt);
                  ^
bcrypt_ext.c:27:19: note: did you mean 'ruby_script'?
/U/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:2747:6: note: 'ruby_script' declared here
void ruby_script(const char* name);
     ^
bcrypt_ext.c:42:25: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
            NIL_P(input) ? 0 : RSTRING_LEN(input));
                               ^~~~~~~~~~~~~~~~~~
/U/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:1007:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/U/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:1003:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bcrypt_ext.c:42:25: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
            NIL_P(input) ? 0 : RSTRING_LEN(input));
                               ^~~~~~~~~~~~~~~~~~
/U/.rbenv/versions/2.7.2/include/ruby-2.7.0/ruby/ruby.h:1008:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
2 warnings and 1 error generated.
make: *** [bcrypt_ext.o] Error 1

make failed, exit code 2

我的 Ruby 版本是 2.7.2。有什么想法可以尝试安装它吗?

我在安装时必须添加一个标志:

gem install bcrypt-ruby -v '3.0.1' -- --with-cflags=-Wno-implicit-function-declaration

这使用 Ruby 2.7.2

成功安装了 gem