I've looked at and tried just about everything on the topic here at Stackoverflow.com and still can't figure this out...
When I 'gem install mysql2' I get a permissions error. when I 'sudo gem install mysql2' I get the following:
Teds-MacBook-Pro:~ tedmartin$ sudo gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
/Users/tedmartin/.rbenv/versions/2.4.1/bin/ruby -r ./siteconf20170420-50202-1nekuvd.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
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
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.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 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
current directory: /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/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
Gem files will remain installed in /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5 for inspection.
Results logged to /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-15/2.4.0-static/mysql2-0.4.5/gem_make.out
Anyone who has an idea, suggestion, tip, fix, etc... I'd be really grateful.
Thanks!
From the answer at this question, running the following worked for me
gem install mysql2 --source 'https://rubygems.org/' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
I ran into this same issue on Mojave, and none of the previous answers worked for me but this commands mentioned in this Github issue comment did
Step 1.
brew install openssl
Step 2.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
In my case I already had openssl installed so it was really the export command that solved the problem.
Make sure openssl is installed on Mac via Homebrew.
brew install openssl
Install mysql2 gem.
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
If the bug is not fixed, this above solution is the last one
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Another solution if the above does not work.
cd /usr/local/Cellar/openssl/1.0.2s/lib/
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib
This worked for me on macOS Catalina:
Make sure you have openssl installed. If not:
brew install openssl
Then do the gem install:
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
Try this:
which mysql
Then, use the output-result to install the gem using the existing mysql installation directory:
gem install mysql2 -- --with-mysql-dir=<mysql-installation-directory>
It away working for me after 2h crazy
Unstall Ruby and Install Ruby v2.6.6
Run command line as Administrator gem install mysql2
Install rails gem install rails
Create new project rails new my_proj -d mysql
Work 100% in Windown
Related
When I try to install cocoapods on my mac using sudo cmd, i.e "sudo gem install cocoapods".
It shows Failed to build gem native extension.
How to install cocoapods on mac,
xxx-MacMini1 ~ % sudo gem install cocoapods
Password:
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.15.5/ext/ffi_c
/usr/local/opt/ruby#2.7/bin/ruby -I /usr/local/Cellar/ruby#2.7/2.7.5/lib/ruby/2.7.0 -r ./siteconf20220318-18160-1id5gxj.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi... 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: /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.15.5/ext/ffi_c
make DESTDIR\= clean
current directory: /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.15.5/ext/ffi_c
make DESTDIR\=
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
compiling ClosurePool.c
compiling DynamicLibrary.c
compiling Function.c
Function.c:867:17: error: implicit declaration of function 'ffi_prep_closure_loc' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ffiStatus = ffi_prep_closure_loc(closure->pcl, &fnInfo->ffi_cif, callback_invoke, closure, code);
^
Function.c:867:17: note: did you mean 'ffi_prep_closure'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi/ffi.h:269:1: note: 'ffi_prep_closure' declared here
ffi_prep_closure(
^
1 error generated.
make: *** [Function.o] Error 1
make failed, exit code 2
Gem files will remain installed in /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.15.5 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/ffi-1.15.5/gem_make.out
How do I fix this issue?
Looks like you have a Ruby issue. Try installing version 2.6.3 using:
sudo gem install cocoapods -v 2.6.3
and then try to run sudo gem install cocoapods. If this didn't work, try the following:
Open terminal and run
curl -L https://get.rvm.io | bash -s stable
Then
rvm install ruby-2.6
This would install the ruby for you if its not yet installed. After this just update ruby to the new version using
rvm use ruby-2.6.3
Make ruby 2.6.3 your default
rvm --default use 2.6.3
Then hopefully you can run
sudo gem install cocoapods
I'm having problems installing Rmagick gem on my M1 Macbook. I installed the latest version of ImageMagick via brew arch -arm64 brew install imagemagick and tested it with the following commands:
magick logo: logo.gif
identify logo.gif
Once I confirmed it was working correctly I added the rmagick gem to my Gemfile.
Below is the output of the bundle install command.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2/ext/RMagick
/Users/user/.rvm/rubies/ruby-2.7.2/bin/ruby -I /Users/user/.rvm/rubies/ruby-2.7.2/lib/ruby/site_ruby/2.7.0 -r ./siteconf20210721-75512-tve65x.rb extconf.rb
checking for brew... yes
checking for Ruby version >= 2.3.0... yes
checking for pkg-config... yes
checking for forced use of ImageMagick 6... no
checking for outdated ImageMagick version (<= 6.7.7)... no
checking for gcc... yes
checking for __GNUC__... yes
checking for MagickCore/MagickCore.h... yes
checking for rb_gc_adjust_memory_usage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... yes
checking for posix_memalign() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... yes
checking for malloc_usable_size() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for malloc_size() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... yes
checking for _aligned_msize() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for GetImageChannelEntropy() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for SetImageGray() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for SetMagickAlignedMemoryMethods() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,sys/types.h,MagickCore/MagickCore.h... no
checking for malloc.h... no
checking for malloc/malloc.h... yes
creating extconf.h
creating Makefile
======================================================================
Wed 21 Jul 21 07:25:56
This installation of RMagick 4.2.2 is configured for
Ruby 2.7.2 (x86_64-darwin20) and ImageMagick 7.1.0
======================================================================
Configured compile options: {:magick_version=>"7.1.0", :local_libs=>" -L/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/lib -lMagickCore-7.Q16HDRI", :cflags=>" -Xpreprocessor -fopenmp
-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/include/ImageMagick-7 -std=gnu99", :cppflags=>" -Xpreprocessor -fopenmp
-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/include/ImageMagick-7", :ldflags=>"
-L/opt/homebrew/Cellar/imagemagick/7.1.0-4_1/lib -lMagickCore-7.Q16HDRI", :defs=>[], :config_h=>"Makefile"}
current directory: /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2/ext/RMagick
make DESTDIR\= clean
current directory: /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2/ext/RMagick
make DESTDIR\=
compiling rmagick.c
compiling rmdraw.c
compiling rmenum.c
compiling rmfill.c
compiling rmilist.c
compiling rmimage.c
rmimage.c:7552:32: error: use of undeclared identifier 'IsGrayImage'
return has_attribute(self, IsGrayImage);
^
1 error generated.
make: *** [Makefile:245: rmimage.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/user/.rvm/gems/ruby-2.7.2/gems/rmagick-4.2.2 for inspection.
Results logged to /Users/user/.rvm/gems/ruby-2.7.2/extensions/x86_64-darwin-20/2.7.0/rmagick-4.2.2/gem_make.out
An error occurred while installing rmagick (4.2.2), and Bundler cannot continue.
Make sure that `gem install rmagick -v '4.2.2' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
rmagick
Make sure your Ruby, rmagick and ImageMagick are all 64-bit or are all 32-bit. That was my problem on Windows 10 (see Github post you replied to).
I am not able to install the latest version of mysql2 gem for my rails application. I have already tried out the options suggested in this answer. However the older version installed without any errors!
gem uninstall mysql2
gem install mysql2 -v 0.2.6
Following is the error that pops up whenever I try to install the latest version of mysql2 gem
C:\Users\EcoAd>gem install mysql2 -v '0.3.16' -- '--with-mysql-lib="C:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="C:\Program Files\MySQL\MySQL Server 5.6\include"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib="C:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="C:\Program Files\MySQL\MySQL Server 5.6\include"'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe -r ./siteconf20140923-3596-odrqgn.rb extconf.rb --with-mysql-lib="C:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="C:\Program Files\MySQL\MySQL Server 5.6\include"
checking for ruby/thread.h... no
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 --with-mysql-dir=C:\Program Files\MySQL\MySQL Server 5.6
checking for main() in -llibmysql... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make clean
Makefile:165: *** target pattern contains no `%'. Stop.
make
Makefile:165: *** target pattern contains no `%'. Stop.
make failed, exit code 2
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.16 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/mysql2-0.3.16/gem_make.out
C:\Users\EcoAd>
I looked everywhere I can find but can't seem to find a solution to this.
I'm using Xcode 4.5.1 on Lion 10.8.2, and am trying to run bundle for a Rails project and it keeps jamming up on this. I'm using the Thin gem for Heroku.
Bolanos#Jeremys-Mac-mini ⦿-1.9.3 fishfarm $ sudo gem install eventmachine
Password:
Building native extensions. This could take a while...
ERROR: Error installing eventmachine:
ERROR: Failed to build gem native extension.
/Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... yes
creating Makefile
make
compiling binder.cpp
make: g++-4.2: No such file or directory
make: *** [binder.o] Error 1
Gem files will remain installed in /Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0 for inspection.
Results logged to /Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/ext/gem_make.out
For now I'm having to do without Thin. Does anyone have a solution?
Also check for a symlink:
$ sudo ln -s /usr/bin/g++ /usr/bin/g++-4.2
You have to install the Command Line Tools package from developer.apple.com.
Also I was having troubles with the MacOSX10.6.sdk because some headers were missing there, so I installed the MacOSX10.5.sdk and all worked fine.
I had the exact error, and creating a new symlink for the missing resource /usr/bin/g++-4.2 worked for me.
In my setup I pointed at the location in Cellar:
/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
If none of the above work for you, I did
sudo ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++-4.2
and it worked like a charm. Running OS X 10.8.2.
You should have both:
Xcode command line tool: Detailed instructions for installation are in "How to install Xcode Command Line Tools".
Apple-gcc* compiler: I should mention that compiling with gcc48 and gcc49 fails. Therefore, installing apple-gcc42 (if you don't have) and choosing the compiler via MacPorts will solve the problem. You can see the installed gcc versions using:
port select --list gcc
You should see something like this where "mp-" stands for MacPorts own port:
Available versions for gcc:
apple-gcc42 (active)
current_saved
mp-gcc48
mp-gcc49
If you don't have "apple-gcc*" you may install it via:
port install apple-gcc42
after that chose the compiler:
port select --set gcc apple-gcc42
Now you may run:
gem install eventmachine
This should solve the problem of errors which arise during building gem native extensions on OSX.
I just upgraded from OS X Lion to OS X Mountain Lion.
My rails environment for the most part stayed in tact.
The only steps I had to do to get things back to a good state was:
- Install XCode 4.4
- Install XCode 4.4 Command Line Tools
- Install gcc-4.2
So all that went well.
Here's the issue, almost all my gems install properly when I run bundle install except for one of the most important ones I need - the postgresql gem 'pg'.
And it specifically fails for versions above 0.12.2.
I'm using ruby 1.9.3p125.
I can successfully grab the 0.12.2 pg gem, and versions below, but they give me segmentation faults (I'm guessing because of the version of ruby I'm using).
So this leads me to believe that it's specific to the pg gem, and not my overall environment seeing as other gems install fine.
I also tried re-installing Postgresql to ensure my postgres environment is ok and seems good on that front.
Has anybody been able to install the 'pg' gem version 0.13.0 or above (and more preferrably 0.14.X)?
Here is my stack trace:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/caseyli/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for ruby/st.h... yes
creating extconf.h
creating Makefile
make
compiling pg.c
pg.c: In function ‘pg_s_library_version’:
pg.c:273: warning: implicit declaration of function ‘PQlibVersion’
pg.c: In function ‘Init_pg_ext’:
pg.c:384: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:384: error: (Each undeclared identifier is reported only once
pg.c:384: error: for each function it appears in.)
pg.c:386: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:388: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:390: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1
Gem files will remain installed in /Users/caseyli/.rvm/gems/ruby-1.9.3- p125#elliottfarmequipment/gems/pg-0.14.0 for inspection.
Deefour's comment got it! It was the way I installed PostgreSQL.
I use the PostgreSQL one-click installer which I'm guessing doesn't set up the libpq up properly for Mountain Lion.
Homebrew on the otherhand will build it properly for the OS.
After installing postgres through homebrew
brew install postgresql
I was able to install my gem no problem.
Thanks everybody!
The issue is the location of pg_config. If you use the one-click installer, it is in /Library/PostgreSQL/9.2/bin/pg_config, so this will build your gem just fine:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.2/bin/pg_config
I had the exact same issue; same stack trace as you've posted.
MRI 1.9.3-p286 / OS X 10.8.2 / Postgres 9.0.4 with homebrew.
I solved it by simply doing:
$ brew update
$ brew upgrade postgresql
$ bundle
Hope it works for someone else.
Reinstalling ruby fixed a similar issue I was having after upgrading to Mountain Lion
rvm reinstall 1.9.3
Note: also run the following as it seems the default version resets
rvm --default 1.9.3
For reference I posted the error I was seeing below
gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with pg=/usr/local/Cellar/postgresql/9.1.4/bin
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Mac comes with an outdated prebuilt PostgreSQL client installation and pg_config file that comes with it conflicts with any new PostgreSQL server & client installations.
Installing ruby gem with a fully qualified file name of pg_config overrides default known location of pg_config and installation succeeds.
Current location of pg_config by one click installer by EnterpriseDB: /Library/PostgreSQL/bin/pg_config
This command finally worked for me.
CrashMX2$ gem install pg -- --with-pg-config=/Library/PostgreSQL/bin/pg_config
I have had the same problem but reinstalling postgresql with homebrew did not solve it. However, this command did it for me:
sudo env ARCHFLAGS="-arch x86_64" gem install pg
I was able to get it to work by installing the Postgres.app from Heroku and removing my existing postgresql installation. You can download the app here:
http://postgresapp.com/
brew remove postgresql
bundle install
If you didn't use brew, here's a link to more uninstall docs from Postgres.app
http://postgresapp.com/documentation#toc_16
I just got mine up and running via this ticket:
How can I pass a parameter for gem installation when I run bundle install?
bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install
Like Matt, Ranjan, and Peter Mellett all say, you have to get the right pg_config location, and Mountain Lion comes with a different location that doesn't seem to play well with rubygems, so if you find your old version like
/Library/PostgreSQL/bin/pg_config
then you can set that in the bundle config before installing.
My situation was upgrading from Lion to Mountain Lion.
Homebrew installed pg_ctl in /usr/local/bin/pg_ctl, so the command for me was:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_ctl
Fro those, who are using Kubuntu 13.04 and installed pg with one click tool, pg config is in other folder, so command:
gem install pg -- --with-pg-config=/opt/PostgreSQL/9.3/bin/pg_config