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

dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info #843

Closed
tapajos opened this issue Apr 26, 2017 · 28 comments
Closed

Comments

@tapajos
Copy link

tapajos commented Apr 26, 2017

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
@sodabrew
Copy link
Collaborator

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

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

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

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

It only happens using mysql-connector-c, with mysql installed it compiles.

I don't want to have the full mysql installed on that machine since the database is running in a separated container.

@sodabrew
Copy link
Collaborator

Interesting. What version of mysql-connector-c does brew provide?

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

mysql-connector-c: stable 6.1.9 (bottled)

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

The same happens using the --build-from-source instead of the bottled version

@sodabrew
Copy link
Collaborator

This is an odd one: ld: library not found for -l-lpthread

Could you post the output from mysql_config ?

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

Sure. There we go.

$ $(brew --prefix mysql-connector-c)/bin/mysql_config
Usage: /usr/local/opt/mysql-connector-c/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/local/opt/mysql-connector-c/include ]
        --cxxflags       [-I/usr/local/opt/mysql-connector-c/include ]
        --include        [-I/usr/local/opt/mysql-connector-c/include]
        --libs           [-L/usr/local/opt/mysql-connector-c/lib -l ]
        --libs_r         [-L/usr/local/opt/mysql-connector-c/lib -l ]
        --plugindir      [/usr/local/Cellar/mysql-connector-c/6.1.9/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [6.1.9]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/local/opt/mysql-connector-c/include]
                pkglibdir     [/usr/local/opt/mysql-connector-c/lib]
                plugindir     [/usr/local/Cellar/mysql-connector-c/6.1.9/lib/plugin]

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

One more thing... I'm having the same issue on three machines.

I'm convinced that it is not a !("works on my machine") thing. :-)

@sodabrew
Copy link
Collaborator

sodabrew commented Apr 26, 2017

The stray -l in --libs [-L/usr/local/opt/mysql-connector-c/lib -l ] is causing one of the errors, because it's concatenating with -lpthread, and turning into -l-lpthread.

@tapajos
Copy link
Author

tapajos commented Apr 26, 2017

@sodabrew can I fix it passing the flags in a different way? how?

@sodabrew
Copy link
Collaborator

Not as easily. I think the better solution is to figure out where this empty argument is coming from in the HomeBrew recipe for this package.

@sodabrew
Copy link
Collaborator

There's nothing about this formula that is obviously wrong in any way:
https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql-connector-c.rb

So... I'd really like to figure out where those incomplete arguments are coming from.

According to the gcc documentation (https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html) a -l command-line option can never stand alone without a value.

-llibrary
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

@tapajos
Copy link
Author

tapajos commented Apr 27, 2017

I downloaded the official version from https://dev.mysql.com/downloads/file/?id=467892 and the output is the same:

$ ./bin/mysql_config
Usage: ./bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/include ]
        --cxxflags       [-I/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/include ]
        --include        [-I/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/include]
        --libs           [-L/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/lib -l ]
        --libs_r         [-L/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/lib -l ]
        --plugindir      [/usr/local/mysql/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [6.1.9]
        --variable=VAR   VAR is one of:
                pkgincludedir [/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/include]
                pkglibdir     [/Users/tapajos/Downloads/mysql-connector-c-6.1.9-macos10.12-x86_64/lib]
                plugindir     [/usr/local/mysql/lib/plugin]

@tapajos
Copy link
Author

tapajos commented Apr 27, 2017

output for 6.1.6 is a little bit different.

$ ./bin/mysql_config
Usage: ./bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/include]
        --cxxflags       [-I/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/include]
        --include        [-I/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/include]
        --libs           [-L/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/lib  -lmysqlclient]
        --libs_r         [-L/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/lib  -lmysqlclient]
        --plugindir      [/usr/local/mysql/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [6.1.6]
        --variable=VAR   VAR is one of:
                pkgincludedir [/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/include]
                pkglibdir     [/Users/tapajos/Downloads/mysql-connector-c-6.1.6-osx10.8-x86_64/lib]
                plugindir     [/usr/local/mysql/lib/plugin]

@sodabrew
Copy link
Collaborator

The 6.1.6 output will work. The missing library in 6.1.9 is the MySQL-connector-c itself (-lmysqlclient) which both makes sense and is the most unexpected.

Are these compiled yourself or binary brew jars that came from the homebrew community servers?

@tapajos
Copy link
Author

tapajos commented Apr 27, 2017

6.1.6 compiled but I had the same Symbol not found error.

For 6.1.9 I had the same output using --build-from-source or bottled version. Also, the same output using the one in mysql page.

@sodabrew
Copy link
Collaborator

Aha, that's when the issue switched between Symbol not found and the compile/link error.

In both cases, are you using pre-compiled binaries, or compiling them yourself from source code?

@tapajos
Copy link
Author

tapajos commented Apr 27, 2017

I tried with both and got the same error.

@iscreen
Copy link

iscreen commented Apr 30, 2017

you can try brew install mariadb-connector-c it's work for me

@tapajos
Copy link
Author

tapajos commented Apr 30, 2017 via email

@tapajos
Copy link
Author

tapajos commented May 1, 2017

@iscreen mariadb-connector-c worked for me. Thank you!

@sodabrew should I close it or this issue still relevant for mysql2 core team?

@tapajos
Copy link
Author

tapajos commented May 1, 2017

As reference:

$ /usr/local/opt/mariadb-connector-c/bin/mariadb_config
Copyright 2011-2015 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: /usr/local/opt/mariadb-connector-c/bin/mariadb_config [OPTIONS]
  --cflags        [-I/usr/local/Cellar/mariadb-connector-c/2.2.2/include/mariadb -I/usr/local/Cellar/mariadb-connector-c/2.2.2/include/mariadb/mysql ]
  --include       [-I/usr/local/Cellar/mariadb-connector-c/2.2.2/include/mariadb -I/usr/local/Cellar/mariadb-connector-c/2.2.2/include/mariadb/mysql]
  --libs          [-L/usr/local/Cellar/mariadb-connector-c/2.2.2/lib/mariadb -lmariadb -lssl /usr/lib/libiconv.dylib -ldl -lm -lpthread]
  --libs_r        [-L/usr/local/Cellar/mariadb-connector-c/2.2.2/lib/mariadb -lmariadb -lssl /usr/lib/libiconv.dylib -ldl -lm -lpthread]
  --version       [5.5.1]
  --socket        [/tmp/mysql.sock]
  --port          [3306]
  --plugindir     [/usr/local/Cellar/mariadb-connector-c/2.2.2/mariadb/lib/plugin]

@sodabrew
Copy link
Collaborator

sodabrew commented May 1, 2017

Glad to hear that the MariaDB Connector/C works!

I still strongly suspect that the problem is with the HomeBrew mysql-connector-c build, but I don't have any specific "smoking gun" to point at.

@sodabrew sodabrew closed this as completed May 1, 2017
@tapajos
Copy link
Author

tapajos commented May 1, 2017

@sodabrew I disagree that the problem is with the HomeBrew mysql-connector-c build because it is also happening with the version downloaded from mysql official page.

I suspect that the problem is with the mysql-connector-c itself.

@sodabrew
Copy link
Collaborator

sodabrew commented May 1, 2017

I disagree that the problem is with the HomeBrew mysql-connector-c build because it is also happening with the version downloaded from mysql official page.

I missed that bit, thanks for clarifying. Is that a binary version downloaded from mysql.com, or source code that you compiled?

@tapajos
Copy link
Author

tapajos commented May 1, 2017

The binary version.

@pedrosanta
Copy link

pedrosanta commented Jun 19, 2017

Hi there, also had this issue. Ruby 2.2.5, mysql2 0.4.5, mysql-connector-c 6.1.10.

Installing/compiling using MariaDB connector also fixed it for me, brew install mariadb-connector-c.

In a similar situation as @tapajos, have MySQL server on a different container, don't want to have mysql installed on this machine. Seems to be a mysql-connector-c issue indeed.

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

4 participants