macOS Ventura導致無法安裝'mysql2',原因是'ld: library not found for -lzlib'
P粉156415696
P粉156415696 2023-11-11 08:40:10
0
2
956

無法使用 bundle install 安裝 mysql2。 我這樣問是因為有些網站和部落格已經展示瞭如何解決由sslzstd 引起的問題,但我找不到由zlib 引起的解決方案。有其他人遇到同樣的問題嗎?

順便說一句,我在本地運行 bundle install,而不是在 docker 上運行。

  • 作業系統:Ventura(13.3.1)
  • Xcode: 14.3
  • 紅寶石:3.1.4
  • 導軌:6.1
  • mysql2:0.5.5

已經完成:

  • 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粉156415696
P粉156415696

全部回覆(2)
P粉748218846

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粉009186469

您好,要修正相同的錯誤,我已經在根專案上建立了一個檔案:帶有此參數的 .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/

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板