macOS Ventura entraîne l'échec de l'installation de « mysql2 » en raison de « ld : bibliothèque introuvable pour -lzlib »
P粉156415696
P粉156415696 2023-11-11 08:40:10
0
2
917

Non disponible bundle install 安装 mysql2. Je pose cette question car certains sites Web et blogs ont montré comment résoudre les solutions causées par sslzstd 引起的问题,但我找不到由 zlib. Quelqu'un d'autre a-t-il rencontré le même problème ?

BTW, j'utilise bundle install localement, pas sur Docker.

  • Système d'exploitation : Ventura(13.3.1)
  • Xcode : 14.3
  • Rubis : 3.1.4
  • Rail : 6.1
  • mysql2:0.5.5

Déjà terminé :

  • brew 安装 mysql、openssl@3、zstd、zlib

Voici la sortie du journal.

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

Ce que j'ai essayé

・Exécution 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"

・Ajoutez les éléments suivants, qui ne sont pas affichés dans brew info zlib mais sont mentionnés dans les réponses ici.

export DYLD_LIBRARY_PATH=/opt/homebrew/opt/zlib/lib:$DYLD_LIBRARY_PATH

·Réinstaller命令行工具 by xcode-select --install

Résultat :

  • Il n'y a aucun changement dans le journal de sortie.
  • Ne peut pas être regroupé et installé mysql2


P粉156415696
P粉156415696

répondre à tous(2)
P粉748218846

La solution proposée par Fyorden a fonctionné pour moi, mais dans mon cas, elles ont été installées par homebrew, donc elles étaient dans des chemins différents. J'ai édité le fichier dans le projet racine .bundle/config en utilisant les paramètres :

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

Bonjour, pour corriger la même erreur, j'ai créé un fichier sur le projet racine : .bundle/config avec ce paramètre

---
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"

Je pense qu'il s'agit d'un bug avec le dernier package MySQL Brew

Je me suis inspiré de https://prabinpoudel .com.np/notes/error-while-installing-mysql2-in-m1-mac/

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal