Rails mysql2 Gem 설치 실패시

rails·2021년 11월 15일
0

시행착오

목록 보기
5/7

Ruby 버전을 2.7에서 3.0으로 업데이트 한 뒤에 아래와 같은 에러가 발생 하며 MySql잼이 설치가 실패 하였다.

M1 맥북이라 호환성 문제가 있나 싶었는데 그건 아니었다.


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

    current directory: /Users/max/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.3/ext/mysql2
/Users/max/.rvm/rubies/ruby-3.0.0/bin/ruby -I /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0 -r ./siteconf20211115-11666-wrzx44.rb
extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.0.27/lib
-----
creating Makefile

current directory: /Users/max/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/max/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
client.c:787:14: warning: incompatible function pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of
type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
  rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
             ^~~~~~~~~~~~~
/Users/max/.rvm/rubies/ruby-3.0.0/include/ruby-3.0.0/ruby/internal/iterator.h:51:25: note: passing argument to parameter here
VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
                        ^
client.c:795:16: warning: incompatible function pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of
type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
    rb_rescue2(do_query, (VALUE)&async_args, disconnect_and_raise, self, rb_eException, (VALUE)0);
               ^~~~~~~~
/Users/max/.rvm/rubies/ruby-3.0.0/include/ruby-3.0.0/ruby/internal/iterator.h:51:25: note: passing argument to parameter here
VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
                        ^
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/max/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/max/.rvm/gems/ruby-3.0.0/extensions/arm64-darwin-21/3.0.0/mysql2-0.5.3/gem_make.out

  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:90:in `run'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:42:in `block in make'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:34:in `each'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:34:in `make'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/ext_conf_builder.rb:64:in `block in build'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/tempfile-0.1.2/lib/tempfile.rb:317:in `open'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:156:in `build_extension'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:190:in `block in build_extensions'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:187:in `each'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/ext/builder.rb:187:in `build_extensions'
  /Users/max/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/installer.rb:821:in `build_extensions'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/rubygems_gem_installer.rb:71:in `build_extensions'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/source/rubygems.rb:200:in `install'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/installer/parallel_installer.rb:186:in `do_install'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/worker.rb:62:in `apply_func'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/worker.rb:54:in `loop'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/worker.rb:54:in `process_queue'
  /Users/max/.rvm/gems/ruby-3.0.0/gems/bundler-2.2.31/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads'

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.

In Gemfile:
  mysql2

해결법

Gemfile.lock을 삭제 하고 새로 bundle install 한다.

아래 명령어로 mysql경로를 지정 해준다.

gem install mysql2 -- \
 --with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.27/lib \
 --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.27 \
 --with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.27/bin/mysql_config \
 --with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.27/include

깔끔하게 설치 되었다.

profile
rails

0개의 댓글