无法使用 bundle install
安装 mysql2
。
我这样问是因为有些网站和博客已经展示了如何解决由 ssl
、zstd
引起的问题,但我找不到由 zlib
引起的解决方案。有其他人遇到同样的问题吗?
顺便说一句,我在本地运行 bundle install
,而不是在 docker 上运行。
已经完成:
brew 安装 mysql、openssl@3、zstd、zlib
这是日志输出。
Fetching gem metadata from https://rubygems.org/.......... Resolving dependencies... Using rake 13.0.6 Using concurrent-ruby 1.2.2 Using minitest 5.18.0 Using zeitwerk 2.6.8 Using websocket-extensions 0.1.5 Using erubi 1.12.0 Using racc 1.6.2 Using date 3.3.3 Using rack 2.2.7 Using bindex 0.8.1 Using bundler 2.3.26 Using marcel 1.0.2 Using mini_mime 1.1.2 Using timeout 0.3.2 Using rb-fsevent 0.11.2 Using crass 1.0.6 Using msgpack 1.7.0 Using builder 3.2.4 Using byebug 11.1.3 Using semantic_range 3.0.0 Using method_source 1.0.0 Using nio4r 2.5.9 Using spring 4.1.1 Using turbolinks-source 5.2.0 Using thor 1.2.1 Using i18n 1.13.0 Using nokogiri 1.14.3 (arm64-darwin) Using rack-test 2.1.0 Using ffi 1.15.5 Using websocket-driver 0.7.5 Using tzinfo 2.0.6 Using sprockets 4.2.0 Using net-protocol 0.2.1 Using rack-proxy 0.7.6 Using bootsnap 1.16.0 Using puma 5.6.5 Using tilt 2.1.0 Using turbolinks 5.2.1 Using rack-mini-profiler 2.3.4 Using loofah 2.20.0 Using net-imap 0.3.4 Using net-smtp 0.3.3 Using rb-inotify 0.10.1 Using sassc 2.4.0 Using net-pop 0.1.2 Using rails-html-sanitizer 1.5.0 Using lis ten 3.8.0 Using activesupport 6.1.7.3 Using mail 2.8.1 Using rails-dom-testing 2.0.3 Using globalid 1.1.0 Using activemodel 6.1.7.3 Using actionview 6.1.7.3 Using activejob 6.1.7.3 Using activerecord 6.1.7.3 Using actionpack 6.1.7.3 Using jbuilder 2.11.5 Using railties 6.1.7.3 Using actioncable 6.1.7.3 Using web-console 4.2.0 Using actionmailer 6.1.7.3 Using sprockets-rails 3.4.2 Using activestorage 6.1.7.3 Using webpacker 5.4.4 Using sassc-rails 2.1.2 Using actionmailbox 6.1.7.3 Using actiontext 6.1.7.3 Using sass-rails 6.0.0 Using rails 6.1.7.3 Installing mysql2 0.5.5 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/qounme/Developments/projects/templates/rails-6/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.5/ext/mysql2 /Users/qounme/.rbenv/versions/3.1.4/bin/ruby -I /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0 extconf.rb checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for rb_gc_mark_movable()... yes checking for rb_wait_for_single_fd()... yes checking for rb_enc_interned_str() in ruby.h... yes ----- Using --with-openssl-dir=/Users/qounme/.rbenv/versions/3.1.4/openssl ----- ----- 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_DEFAULT_AUTH in mysql.h... yes 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.33/lib ----- creating Makefile current directory: /Users/qounme/Developments/projects/templates/rails-6/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.5/ext/mysql2 make DESTDIR= sitearchdir=./.gem.20230505-8569-clyohw sitelibdir=./.gem.20230505-8569-clyohw cl ean current directory: /Users/qounme/Developments/projects/templates/rails-6/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.5/ext/mysql2 make DESTDIR= sitearchdir=./.gem.20230505-8569-clyohw sitelibdir=./.gem.20230505-8569-clyohw compiling client.c In file included from client.c:15: ./mysql_enc_name_to_ruby.h:43:1: warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] mysql2_mysql_enc_name_to_rb_hash (str, len) ^ ./mysql_enc_name_to_ruby.h:86:1: warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] mysql2_mysql_enc_name_to_rb (str, len) ^ 2 warnings generated. compiling infile.c compiling mysql2_ext.c compiling result.c result.c:304:35: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] precision = field->length - (field->decimals > 0 ? 2 : 1); ~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. compiling statement.c linking shared-object mysql2/mysql2.bundle ld: library not found for -lzlib 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/qounme/Developments/projects/templates/rails-6/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.5 for inspection. Results logged to /Users/qounme/Developments/projects/templates/rails-6/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-22/3.1.0/mysql2-0.5.5/gem_make.out /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:102:in `run' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:51:in `block in make' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:43:in `each' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:43:in `make' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:42:in `build' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:171:in `build_extension' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:205:in `block in build_extensions' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in `each' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in `build_extensions' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/installer.rb:843:in `build_extensions' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/rubygems_gem_installer.rb:72:in `build_extensions' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/rubygems_gem_installer.rb:28:in `install' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/source/rubygems.rb:207:in `install' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/installer/gem_installer.rb:54:in `install' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/installer/gem_installer.rb:16:in `install_from_spec' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/installer/parallel_installer.rb:186:in `do_install' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/installer/parallel_installer.rb:177:in `block in worker_pool' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/worker.rb:62:in `apply_func' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/worker.rb:57:in `block in process_queue' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/worker.rb:54:in `loop' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/worker.rb:54:in `process_queue' /Users/qounme/.rbenv/versions/3.1.4/lib/ruby/3.1.0/bundler/worker.rb:91:in `block (2 levels) in create_threads' An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue. In Gemfile: mysql2
・执行 brew install zlib
后,将以下内容添加到 .zshrc
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib" export CPPFLAGS="-I/opt/homebrew/opt/zlib/include" export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"
・添加以下内容,这些内容未在 brew info zlib
中显示,但在此处的答案中提到。
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/zlib/lib:$DYLD_LIBRARY_PATH
·重新安装命令行工具
by xcode-select --install
结果:
mysql2
P粉7482188462023-11-12 00:45:58
Fyorden 提出的解决方案对我有用,但就我而言,它们是由自制软件安装的,因此它们位于不同的路径中。我使用参数编辑了根项目 .bundle/config
中的文件:
BUNDLE_BUILD__MYSQL2: "--with-mysql-lib=/opt/homebrew/opt/mysql/lib --with-mysql-dir=/opt/homebrew/opt/mysql --with-mysql-config=/opt/homebrew/opt/mysql/bin/mysql_config \ --with-mysql-include=/opt/homebrew/opt/mysql/include --with-ldflags=-L/opt/homebrew/opt/zlib/lib"
P粉0091864692023-11-12 00:34:18
您好,要纠正相同的错误,我已经在根项目上创建了一个文件:带有此参数的 .bundle/config
--- BUNDLE_BUILD__MYSQL2: "--with-mysql-lib=/usr/local/opt/mysql/lib --with-mysql-dir=/usr/local/opt/mysql --with-mysql-config=/usr/local/opt/mysql/bin/mysql_config \ --with-mysql-include=/usr/local/opt/mysql/include --with-ldflags=-L/usr/local/opt/zlib/lib"
我认为这是最后一个 mysql brew 包的错误
我的灵感来自https://prabinpoudel .com.np/notes/error-while-installing-mysql2-in-m1-mac/