Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't install mysql2 on mac : error "ld: library not found for -lzstd" #1345

Open
dlinah opened this issue Jan 18, 2024 · 4 comments
Open

can't install mysql2 on mac : error "ld: library not found for -lzstd" #1345

dlinah opened this issue Jan 18, 2024 · 4 comments

Comments

@dlinah
Copy link

dlinah commented Jan 18, 2024

Here , is the steps i tried to fix the issue with:

  • reinstall xcode comand line tools
  • installed [email protected]
  • passed zstd dir as an option gem install mysql2 -- --with-openssl-dir=$(brew --prefix [email protected]) --with-zstd-dir=/opt/homebrew/Cellar/zstd/1.5.5

my envirement :

mysql: 8.2.0
zstd: v1.5.5
xcode-select: 2397.
mac : Ventura 13.3

full error:

Installing mysql2 0.5.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    current directory: /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
/Users/joycelee/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb --with-openssl-dir\=/opt/homebrew/opt/[email protected]
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=/opt/homebrew/opt/[email protected]
-----
-----
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.2.0_1/lib
-----
creating Makefile
current directory: /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240117-33849-7e94vq sitelibdir\=./.gem.20240117-33849-7e94vq clean
current directory: /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240117-33849-7e94vq sitelibdir\=./.gem.20240117-33849-7e94vq
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 -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/joycelee/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/joycelee/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-22/3.2.0/mysql2-0.5.5/gem_make.out
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:119:in `run'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:43:in `each'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:43:in `make'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:41:in `build'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:187:in `build_extension'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:221:in `block in build_extensions'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:218:in `each'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:218:in `build_extensions'
  /Users/joycelee/.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/installer.rb:843:in `build_extensions'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/source/rubygems.rb:200:in `install'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/installer/parallel_installer.rb:156:in `do_install'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/installer/parallel_installer.rb:147:in `block in worker_pool'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/worker.rb:62:in `apply_func'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/worker.rb:54:in `loop'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/worker.rb:54:in `process_queue'
  /Users/joycelee/.rvm/gems/ruby-3.2.2/gems/bundler-2.4.10/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'
An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.
In Gemfile:
  mysql2

@Faq
Copy link

Faq commented Jan 19, 2024

  1. MacOS ARM-based, like M1?
  2. For me it seems you use wrong openssl version with ruby 3.2

With correct openssl version if still problem occurs, try #1342

@noahgregory-basis
Copy link

You should add linker flags to the build command so it can find the zstd library.

Here's what I ran:

bundle config --local build.mysql2 "--with-ldflags=-L\`brew --prefix zstd\`/lib"

To explain what this command does, it adds a build.mysql2 key to the local (project-level) config for Bundler (the Ruby gem package manager) with the value --with-ldflags=-L\`brew --prefix zstd\`/lib.

It's not really documented well, but I believe Bundler will take config values with keys of build.{gemname} and pass the value as command line arguments for building the native extensions of that gem.

--with-ldflags=-L\`brew --prefix zstd\`/lib add a flag --with-ldflags and sets it equal to -L\`brew --prefix zstd\`/lib. When evaluated, the \`brew --prefix zstd\` section gets replaced with the result of the brew --prefix zstd (which, for me, is /opt/homebrew/opt/zstd). So the flag becomes --with-ldflags=-L/opt/homebrew/opt/zstd/lib, which is where the library should be.

@dorianmariecom
Copy link

I had to do:

bundle config build.mysql2 '-- --with-cflags="-Wno-error=implicit-function-declaration" --with-ldflags=-L/opt/homebrew/opt/zstd/lib'

@yzgan
Copy link

yzgan commented Feb 26, 2024

With correct openssl version if still problem occurs, try #1342

Thanks @Faq .

I'm having the same issue in Mac M1 machine with ruby 3.3.0, rails 7.1.3.2 and mysql 0.5.6.
The issue resolved with the following.

gem install mysql2 -v 0.5.6 -- --with-ldflags=-L$(brew --prefix zstd)/lib

after successfully installing the mysql2 gem, then do bundle update. Make sure the bundle installing the correct mysql2 dependency version(in my case v0.5.6).

bundle update mysql2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants