I'm trying to install mysql2 gem (0.4.5) on macOS Sierra (10.12.1) and getting the error. I don't have local mysql server, it's remote.
Here is error log:
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/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/Cellar/mysql-connector-c/6.1.9/lib
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.4/mkmf.log
current directory: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.4.4/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
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
Did anyone meet similar error?
Fix:
Edit /usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config, find this line:
libs="$libs -l "
and change it to
libs="$libs -l mysqlclient "
Explanation:
-l-lpthread
The linker does not understand the option -l-lpthread. Two -l-l linker options are jammed up against each other. It is because the library name mysqlclientis missing from the generated make file.
I ran into this issue when trying to build the native extensions for the mysql2 gem on Ruby 2.4.1 using the mysql-connector-c from Home Brew
This was on MacOS 10.12.5.
The generated LIBS variable should look something this:
LIBS = $(LIBRUBYARG_SHARED) -L/usr/local/Cellar/mysql-connector-c/6.1.10/lib -l mysqlclient -lpthread -ldl -lobjc
It appears the variable is expanded from the file /usr/local/Cellar/mysql-connector-c/6.1.10/bin/mysql_config
The libs var in the file mysql_config should contain:
libs="$libs -l mysqlclient "
instead of
libs="$libs -l "
The var embedded_libs may be wrong too?
The mysql-connector-c lib installs and build fine via Home Brew it just appears the file mysql_config is incorrect or generated incorrectly.
Not sure the cause of the issue. Possibly Home Brew, mysql-connector-c, mysql2 gem build process, user environment?
The issue is that you're missing a library as the error message indicates
ld: library not found for -l-lpthread
EDIT:
There seem to be other errors related that may be fixed with the instructions below, namely:
ld: library not found for -lssl
My guess is that you did not install xcode yet which happens to install a few more libraries. Please make sure to install xcode through the official app-store.
It might be necessary to re-install the command-line tools again as well (even if you had xcode installed and just updated it at some point).
xcode-select --install
Let me know if this helped!
I'm not sure if the issue is that the mysql-connector-c formula is broken in Homebrew, or if the issues lies in the mysql2 gem, but you can work around the issue by installing the mysql formula.
Even if you don't need a local MySQL server for development, the version of mysql_config from the mysql formula correctly returns the list of libraries required to link the gem's native extension.
If you already have mysql-connector-c installed:
brew unlink mysql-connector-c
# OR
brew uninstall mysql-connector-c
Install the mysql formula:
brew install mysql
Related
On a fresh Manjaro install, after having installed the Ruby with
pacman -S ruby
I tried to install Jekyll running
gem install bundler jekyll
The bundler has been installed successfully, but the Jekyll installation gave me this error:
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
current directory: /home/jgabrielgruber/.local/share/gem/ruby/3.0.0/gems/ffi-1.15.5/ext/ffi_c
/usr/bin/ruby -I /usr/lib/ruby/3.0.0 -r ./siteconf20220428-5815-4q66ic.rb extconf.rb
checking for ffi.h... yes
checking for ffi_prep_closure_loc() in -lffi... yes
checking for ffi_prep_cif_var()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for whether -pthread is accepted as LDFLAGS... yes
creating extconf.h
creating Makefile
current directory: /home/jgabrielgruber/.local/share/gem/ruby/3.0.0/gems/ffi-1.15.5/ext/ffi_c
make DESTDIR\= clean
current directory: /home/jgabrielgruber/.local/share/gem/ruby/3.0.0/gems/ffi-1.15.5/ext/ffi_c
make DESTDIR\=
make failedNo such file or directory - make
Turns out, on the
make failedNo such file or directory - make
It says that the make command is not installed on Manjaro, to solve this, you need to install it with:
pacman -S make
Attempting to install a specific version Mysql2 Gem. And I get this:
sudo gem install mysql2 -v '0.3.20'
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.2.3/bin/ruby -r ./siteconf20161017-56699-1dsu6v9.rb extconf.rb
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/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/Cellar/mysql/5.7.16/lib
-----
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
For reference I ran brew install mysql beforehand and it ran successfully. Also I tried uninstalling all versions of brew's mysql references just in case.
Is there something im missing? I've looked around and most pages point back to making sure you run brew install mysql which I have.
In case I wasn't more clear with my above explanation, the failure I am getting is after successfully running brew install mysql the error is from trying to install the gem afterwards via gem install mysql2 -v '0.3.20'
Any idea?
Thanks
How to make it work on MacOS Mojave.
Make sure openssl is installed on Mac via Homebrew:
brew install openssl
Then install mysql2 gem following this special way:
gem install mysql2 -v 'x.x.x' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
where x.x.x - specified version of the mysql2 gem.
Just for reference what ended up working was xcode-select --install which seemed to install the OpenSSL libraries which took care of the ld: library not found for -lssl issue.
When trying to run a rails server in my current directory (which is a new rails project), it says that I need to install the mysql2 gem. At first, I had no idea what this meant... Then, I did some poking around, and finally decided to install the gem. However, I am getting this super pesky error (seeing as I just spent 2 hours trying to investigate, and solve another error). I am on the brink of giving up, but I really want to try rails. Please help!
Currently, if I run sudo gem install mysql2, or even as some people told me to do online, gem install mysql -- \ --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config (I have MAMP), it gives me the following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/vicky/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /Applications/MAMP/Library/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 /Applications/MAMP/Library/lib
-----
creating Makefile
make "DESTDIR="
compiling client.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/mpapis/.sm/pkg/active/lib'
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
Gem files will remain installed in /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14 for inspection.
Results logged to /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/ext/mysql2/gem_make.out
Have you considered installing MySQL with homebrew (http://brew.sh/)? MAMP stands for Mac-Apache-MySQL-PHP (the last part of this being the most important). I would suggest just installing MySQL directly on your box (homebrew takes care of all the heavy lifting) and afterwards I doubt you'll have any difficulty installing that gem.
To install homebrew --
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Run brew doctor follow any instructions and then afterwards to install MySQL run brew install mysql and follow any of the instructions it provides for setting up a user, etc...
============= UPDATE ==============
SO, what you'll want to do is use brew this way to install MySQL and then install the gem in the normal fashion - sudo gem install mysql2 assuming this works, then you will be able to switch back to the old MySQL install through MAMP via -
sudo nano /etc/paths
then add this line to the top of the document -
/Applications/MAMP/Library/bin
restart your terminal and then run mysql to double check that you are using the MAMP installation of MySQL, and you'll be good to go.
I have a clean build system as follows
Ubuntu 11.04
Rvm 1.13.5
Ruby 1.9.3p194
Rails 3.2.3
Gem 1.8.24
MySql 5.5.24-1 (installed in /usr/local)
I am trying to install the mysql2 gem (0.3.11) and getting the following problem:
pal#smurf01:~$ sudo gem install mysql2
[sudo] password for pal:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling client.c
client.c: In function 'rb_raise_mysql2_error':
client.c:98:3: warning: ISO C90 forbids mixed declarations and code
client.c: In function 'rb_mysql_client_socket':
client.c:590:3: warning: ISO C90 forbids mixed declarations and code
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.so
/usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.so when searching for -lmysqlclient_r
/usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.a when searching for -lmysqlclient_r
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make: *** [mysql2.so] Error 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
pal#smurf01:~$
First question: Has anyone got Rails mysql2 running with MySql 5.5.1 on Ubuntu? I have it running on another system with 5.1. The gem description is vague on supported MySql versions.
Second question: Has anyone encountered this problem? I± have battled various library issues with the mysql2 gem over the passed year or so but this seems to be different.
Any assistance is gratefully recieved.
BTW: Reverting back to MySql 5.1 is a valid solution!
Regards
Peter
Or just apt-get install libmysqlclient-dev and then gem install mysql2
So the problem appears to have been a missing library and some links. Doing the following solved the issue.
Get the new and install the libmysqlclient-dev deb package kindly provided by Nathan Rennie Waldock
wget http://ppa.launchpad.net/nathan-renniewaldock/ppa/ubuntu/pool/main/m/mysql-5.5/libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb./;l
dpkg -i libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb
Then create some links that mysql2 needs as it can't seem to follow the mysql path
cd /usr/lib/
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.a .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18 .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18.0.0 .
Now happily install the mysql2 gem
sudo gem install mysql2
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysq2l-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
Had the same issue in Ubuntu 12.04 also using the ppa mentioned in the accepted answer.
But also there was no libmysqlclient file on my system with _r in the name.
Googling around I found out that package builders have started to drop the _r suffix from the files, so that might have happened between 11.10 and 12.04.
Also the paths were a bit different to the once mentioned so these are the symlinks that I had to create:
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.a ./libmysqlclient_r.a
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so ./libmysqlclient_r.so
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 ./libmysqlclient_r.so.18
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0 ./libmysqlclient_r.so.18.0.0
I had this problem as well...
I did dpkg -r mysql-devel as when I was trying to do apt-get install libmysqlclient-dev I got an error saying:
Unpacking libmysqlclient-dev (from .../libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb) ... dpkg:
error processing
/var/cache/apt/archives/libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb
(--unpack): trying to overwrite '/usr/bin/mysql_config', which is
also in package mysql-devel 5.5.28-2
After doing this, gem install mysql2 worked! yay :)
I get this error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
I've tried everything here but I still get the error. For some reason when I run locate mysql_config this is the result I get:
/Applications/MAMP/Library/bin/mysql_config
/Applications/MAMP/Library/share/man/man1/mysql_config.1
I tried running sudo gem install mysql2 -- –with-mysql config=/path/you/identified/above/mysql_config twice using each path but I still get the error from above. I downloaded a fresh version of MySql and I have Xcode, but I still get these errors. What am I doing wrong?
Is the MAMP install the only install of mysql you have? If you've installed it from the mysql package then I think mysql_config will be installed in /usr/local/bin/mysql_config, so you might want to try:
sudo gem install mysql2 -- –with-mysql-config==/usr/local/bin/mysql_config
FYI, the /Applications/MAMP/Library/share/man/man1/mysql_config.1 path is clearly wrong. That's pointing to the man file for mysql_config not the actual executable.
Just to be certain, you did try this right? (exactly as written)
sudo gem install mysql2 -- –with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
Also, I'm not sure that mysql packaged with MAMP has the header files you need. You might be best to install mysql from http://dev.mysql.com/downloads/mysql/ and then try to install your gem. In this case I think it will just work.