mysql2: dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info

Problem

I was able to compile mysql2 on my Mac but I’m getting that error requiring it.

$ gem install mysql2 -v0.3.21 -- --with-mysql-include=$(brew --prefix mysql-connector-c)/include --with-mysql-lib=$(brew --prefix mysql-connector-c)/lib/ --with-mysql-config=$(brew --prefix mysql-connector-c)/bin/mysql_config
Building native extensions with: '--with-mysql-include=/usr/local/opt/mysql-connector-c/include --with-mysql-lib=/usr/local/opt/mysql-connector-c/lib/ --with-mysql-config=/usr/local/opt/mysql-connector-c/bin/mysql_config'
This could take a while...

Successfully installed mysql2-0.3.21
Parsing documentation for mysql2-0.3.21
Installing ri documentation for mysql2-0.3.21
Done installing documentation for mysql2 after 0 seconds
1 gem installed
$ ruby -e 'require "mysql2"'
dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
  Referenced from: /Users/tapajos/.gem/ruby/2.3.1/gems/mysql2-0.3.21/lib/mysql2/mysql2.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_get_client_info
  Referenced from: /Users/tapajos/.gem/ruby/2.3.1/gems/mysql2-0.3.21/lib/mysql2/mysql2.bundle
  Expected in: flat namespace

Abort trap: 6

System details

OS X: 10.12.3 XCode: 8.3 mysql-connector-c: 6.1.9 (installed using homebrew) gem environment:

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin16]
  - INSTALLATION DIRECTORY: /Users/tapajos/.gem/ruby/2.3.1
  - USER INSTALLATION DIRECTORY: /Users/tapajos/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /Users/tapajos/.rubies/ruby-2.3.1/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/tapajos/.gem/ruby/2.3.1/bin
  - SPEC CACHE DIRECTORY: /Users/tapajos/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/tapajos/.rubies/ruby-2.3.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-16
  - GEM PATHS:
     - /Users/tapajos/.gem/ruby/2.3.1
     - /Users/tapajos/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/tapajos/.gem/ruby/2.3.1/bin
     - /Users/tapajos/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/bin
     - /Users/tapajos/.rubies/ruby-2.3.1/bin
     - /usr/local/bin
     - /usr/local/sbin
     - /usr/local/Cellar/mysql55/5.5.49/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Users/tapajos/dotfiles/bin

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28

Most upvoted comments

Use just one --with-mysql-xxx option. Use --with-mysql-config, that allows the mysql_config tool to report the best information for compiling and linking. https://github.com/brianmario/mysql2#configuration-options

Hi @sodabrew,

Using only ---with-mysql-config it fails to compile the gem.

Using --with-mysql-dir it compiles without any error or warning but keeps failing on the require.

Also tried with --with-mysql-config and --with-mysql-rpath.

$ gem install mysql2 -v0.3.21 -- --with-mysql-config=$(brew --prefix mysql-connector-c)/bin/mysql_config
Fetching: mysql2-0.3.21.gem (100%)
Building native extensions with: '--with-mysql-config=/usr/local/opt/mysql-connector-c/bin/mysql_config'
This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

    current directory: /Users/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21/ext/mysql2
/Users/tapajos/.rubies/ruby-2.3.3/bin/ruby -r ./siteconf20170426-15608-15jy9z.rb extconf.rb --with-mysql-config=/usr/local/opt/mysql-connector-c/bin/mysql_config
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/opt/mysql-connector-c/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/opt/mysql-connector-c/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/tapajos/.gem/ruby/2.3.3/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.3.21/mkmf.log

current directory: /Users/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
client.c:367:33: warning: implicit conversion loses integer precision: 'long' to 'unsigned int' [-Wshorten-64-to-32]
        elapsed_time = end_time - start_time;
                     ~ ~~~~~~~~~^~~~~~~~~~~~
client.c:1152:56: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
  mysql2rb = mysql2_mysql_enc_name_to_rb(charset_name, charset_name_len);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~               ^~~~~~~~~~~~~~~~
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:189:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (i = 0; i < (len - 1); i++) {
              ~ ^  ~~~~~~~
1 warning generated.
linking shared-object mysql2/mysql2.bundle
ld: library not found for -l-lpthread
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/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21 for inspection.
Results logged to /Users/tapajos/.gem/ruby/2.3.3/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.3.21/gem_make.out
$ gem install mysql2 -v0.3.21 -- --with-mysql-config=$(brew --prefix mysql-connector-c)/bin/mysql_config --with-mysql-rpath=$(brew --prefix mysql-connector-c)/lib
Building native extensions with: '--with-mysql-config=/usr/local/opt/mysql-connector-c/bin/mysql_config --with-mysql-rpath=/usr/local/opt/mysql-connector-c/lib'
This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

    current directory: /Users/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21/ext/mysql2
/Users/tapajos/.rubies/ruby-2.3.3/bin/ruby -r ./siteconf20170426-18087-6g53ff.rb extconf.rb --with-mysql-config=/usr/local/opt/mysql-connector-c/bin/mysql_config --with-mysql-rpath=/usr/local/opt/mysql-connector-c/lib
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/opt/mysql-connector-c/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting mysql rpath to /usr/local/opt/mysql-connector-c/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/tapajos/.gem/ruby/2.3.3/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.3.21/mkmf.log

current directory: /Users/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
client.c:367:33: warning: implicit conversion loses integer precision: 'long' to 'unsigned int' [-Wshorten-64-to-32]
        elapsed_time = end_time - start_time;
                     ~ ~~~~~~~~~^~~~~~~~~~~~
client.c:1152:56: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
  mysql2rb = mysql2_mysql_enc_name_to_rb(charset_name, charset_name_len);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~               ^~~~~~~~~~~~~~~~
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:189:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
  for (i = 0; i < (len - 1); i++) {
              ~ ^  ~~~~~~~
1 warning generated.
linking shared-object mysql2/mysql2.bundle
ld: library not found for -l-lpthread
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/tapajos/.gem/ruby/2.3.3/gems/mysql2-0.3.21 for inspection.
Results logged to /Users/tapajos/.gem/ruby/2.3.3/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.3.21/gem_make.out