An error occurred while installing thin (1.7.2), and Bundler cannot continue.の解決方法

Railsの環境構築中にbundle installをしたところ、以下のようなエラーが発生。どうやらthinというgemがエラーの原因となってる模様。とりあえずthinをインストールする必要があるみたい。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/asakura1041/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thin-1.7.2/ext/thin_parser
/Users/asakura1041/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20211008-90288-bo55z4.rb extconf.rb
checking for main() in -lc... yes
creating Makefile

current directory: /Users/asakura1041/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thin-1.7.2/ext/thin_parser
make "DESTDIR=" clean

current directory: /Users/asakura1041/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thin-1.7.2/ext/thin_parser
make "DESTDIR="
compiling parser.c
parser.c:31:18: warning: unused variable 'http_parser_en_main' [-Wunused-const-variable]
static const int http_parser_en_main = 1;
                 ^
1 warning generated.
compiling thin.c
thin.c:242:3: error: implicit declaration of function 'thin_http_parser_init' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  thin_http_parser_init(hp);
  ^
thin.c:242:3: note: did you mean 'http_parser_init'?
./parser.h:41:5: note: 'http_parser_init' declared here
int http_parser_init(http_parser *parser);
    ^
.
.
省略
.
,
thin.c:359:10: error: implicit declaration of function 'thin_http_parser_has_error' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  return thin_http_parser_has_error(http) ? Qtrue : Qfalse;
         ^
thin.c:374:10: error: implicit declaration of function 'thin_http_parser_is_finished' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  return thin_http_parser_is_finished(http) ? Qtrue : Qfalse;
         ^
9 errors generated.
make: *** [thin.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/asakura1041/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thin-1.7.2 for inspection.
Results logged to /Users/asakura1041/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-19/2.5.0/thin-1.7.2/gem_make.out

An error occurred while installing thin (1.7.2), and Bundler cannot continue.
Make sure that `gem install thin -v '1.7.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mailcatcher was resolved to 0.2.4, which depends on
    skinny was resolved to 0.2.2, which depends on
      thin

エラー文の中にある以下のコマンドを実行しても、ダメだった。

gem install thin -v '1.7.2' --source 'https://rubygems.org/'

【解決した方法】

gem install thin -v '1.7.2' -- --with-cflags="-Wno-error=implicit-function-declaration"

なんか後ろに変なオプションを付けて実行したところ、解消できました。

-vの後ろのバージョンだけ自分の環境に出ているエラーに合わせて変えてみてください。

タイトルとURLをコピーしました