Currently trying to install the mysql2 gem on redhat. This is what I'm getting after running gem install
gem install mysql2 -v 0.3.18 -- --with-mysql-config=/usr/bin/mysql_config
checking for ruby/thread.h... *** 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.
It looks like most people who get a similar error need to install mysql dev/lib packages. The packages are already installed and up to date. The mkmf.log file looks like this:
"gcc -o conftest -I/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/x86_64-linux -I/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/backward
-I/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0 -I. -I/home/zdev/.rbenv/versions/2.2.0/include -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math -ggdb3
-Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings
-Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L.
-L/home/zdev/.rbenv/versions/2.2.0/lib -Wl,-R/home/zdev/.rbenv/versions/2.2.0/lib -L/home/zdev/.rbenv/versions/2.2.0/lib -lruby-static -lpthread -lrt
-ldl -lcrypt -lm -lc"
In file included from /home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby.h:33,
from conftest.c:1:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:107: error: size of array 'ruby_check_sizeof_long' is negative
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:111: error: size of array 'ruby_check_sizeof_voidp' is negative
In file included from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby.h:33,
from conftest.c:1:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h: In function 'rb_int2num_inline':
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1303: warning: comparison is always true due to limited range of data type
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1303: warning: comparison is always true due to limited range of data type
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h: In function 'rb_uint2num_inline':
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1313: warning: comparison is always true due to limited range of data type
In file included from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/intern.h:35,
from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1710,
from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby.h:33,
from conftest.c:1:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/st.h: At top level:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/st.h:52: error: size of array 'st_check_for_sizeof_st_index_t' is negative
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
The errors in the log file are produced by sanity checks like this:
typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1];
What could be the cause of this issue? gcc and mysql are both 64 bit - are there any other binaries/libs that would cause this issue?
For the record, there is a copy of the mysql2 gem already installed on this system. It was installed a couple years ago by the original developer, and is tied to a ruby install in /usr/bin. I'm trying to migrate a project over to using a ruby managed by rbenv. From a clean ruby install made through rbenv, bundle install will work flawlessly on our ubuntu box, but it trips up with the mysql2 gem on this system.
Related
I upgraded the macos to Mojave and reinstalled xcode, xcode CLT, ruby, etc. Then when I tried:
gem install nokogiri
I got the following error (installing other gems gave similar error):
ERROR: Failed to build gem native extension.
current directory: /usr/local/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/usr/local/opt/ruby/bin/ruby -r ./siteconf20181209-20884-etfc5r.rb extconf.rb
checking if the C compiler accepts ... *** 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 checked the mkmf.log, which contains the following:
"clang -o conftest -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/x86_64-darwin18 -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby/backward -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0 -I. -I/usr/local/opt/libyaml/include -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens -fno-common -pipe conftest.c -L. -L/usr/local/Cellar/ruby/2.5.3_1/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -lruby.2.5.3 -lpthread -ldl -lobjc "
In file included from conftest.c:1:
In file included from /usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby.h:33:
In file included from /usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby/ruby.h:29:
The text went on like this for a while. I also cd to the nokogiri folder and directly run extconf.rb, and got the following error:
checking if the C compiler accepts ... *** 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.`
Provided configuration options:
--with-opt-dir
--with-opt-include
... (skipped similar content for brevity and continued below)
usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/mkmf.rb:456:in 'try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
I tried to install xcode. I also installed the header and acknowledged the license. I at first thought it has to do with GCC, but the mkmf file showed that the problem is with Clang.
Hope someone can help.
I had to run the following cryptic commands to get nokogiri installed. Basically this entails getting my C compiler working in mac osx Mojave, after having everything working fine in a previous OS (Yosemite I think it was...)
This is an (somewhat) obvious step when upgrading osx:
xcode-select --install
I also had to do this, which I never would've known how to do without google and this post
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Finally, I had to agree to the xcode license (found I had to do this via the makefile logs when install of nokogiri failed...)
sudo xcodebuild -licence
It'll prompt you to eventually type "agree"
Finally, continuing with bundle works as expected for a new rails project that includes nokogiri. Success!
When I try to running bundle install I see:
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/extensions/x86-
mingw32/2.3.0/nio4r-2.1.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/nio4r-2.1.0 for
inspection.
Results logged to
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/extensions/x86-
mingw32/2.3.0/nio4r-2.1.0/gem_make.out
An error occurred while installing nio4r (2.1.0), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.1.0'` succeeds before bundling.
I am using Windows 10, Ruby 2.3.3, Rails 5.0.2.
mkmf.log content is:
"gcc -o conftest.exe -IC:/RailsInstaller/Ruby2.3.0/include/ruby-2.3.0/i386-
mingw32 -IC:/RailsInstaller/Ruby2.3.0/include/ruby-2.3.0/ruby/backward -
IC:/RailsInstaller/Ruby2.3.0/include/ruby-2.3.0 -I. -DFD_SETSIZE=2048 -
D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -
O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-
parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -
Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-
statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-
packed-bitfield-compat conftest.c -L. -LC:/RailsInstaller/Ruby2.3.0/lib -L.
-lmsvcrt-ruby230 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
Checked program was:
#include "ruby.h"
#include <winsock2.h>
#include <windows.h>
int main(int argc, char **argv)
{
return 0;
}
If other gems have same error (and it's initial bundle install), try to change in gemfile source 'https://rubygems.org' to source 'http://rubygems.org'.
I had this problem on windows in corporate network, and problem somewhere with ssl. That solution works for me, but i know, it isn't best solution.
But it's a bad recommendation, if any other gem installed with success.
I have updated xcode to 5.1 and install the command line tools from preference->downloads page.
But when I try to install ruby gems (e.g. sqlite3, nokogiri), it gives errors like this:
*** 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.
And then I checked the mkmf.log:
" -o conftest -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0/x86_64-darwin13.0 -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0/ruby/backward -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/Users/travis/.sm/pkg/active/include -fPIC -mmacosx-version-min=10.7 -pipe -Wno-error=unused-command-line-argument-hard-error-in-future conftest.c -L. -L/Users/alun/.rvm/rubies/ruby-2.1.2/lib -lxml2 -arch x86_64 -lruby-static -framework CoreFoundation -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
I searched but didn't find similar mkmf.log
It seems the build command doesn't specify gcc or any other things.
Finally I've solved my problem, by reinstall xcode and command line tools, and then reinstall ruby with rvm
This is the error I got:
MacBook-Pro:myapp marcamilly$ gem install json -v 1.1.3
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
creating Makefile
make
gcc -I. -I/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-darwin10.4.0 -I/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -Wall -o parser.o -c parser.c
parser.rl:2:16: error: re.h: No such file or directory
In file included from parser.rl:3:
/Users/marcamilly/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward/st.h:2:2: warning: #warning use "ruby/st.h" instead of bare "st.h"
parser.rl: In function ‘cParser_initialize’:
parser.rl:499: error: ‘struct RHash’ has no member named ‘tbl’
parser.rl:511: error: ‘struct RHash’ has no member named ‘tbl’
parser.rl:518: error: ‘struct RHash’ has no member named ‘tbl’
make: *** [parser.o] Error 1
Gem files will remain installed in /Users/marcamilly/.rvm/gems/ruby-1.9.2-p0/gems/json-1.1.3 for inspection.
Results logged to /Users/marcamilly/.rvm/gems/ruby-1.9.2-p0/gems/json-1.1.3/ext/json/ext/parser/gem_make.out
Any thoughts on what how I can fix this?
I believe that I might have had json installed as apart of another project (a Rails project) previously, but now I am trying to install this specific one, to be used with Sinatra and this is the error I get.
Thanks.
It seems that I had to have ruby 1.8.7 chosen as the current version of Ruby before installing this gem.
I finally got it installed properly.
a CentOS 64-bit Server with Ruby 1.8.7 & 1.9.2
{{no RVM, need it without RVM...
currently all Ruby1.9.2 binaries are ruby19 and similarly accessible,
so no mapping of gem-path or anything of that sort is there}}
is giving error while installing gem 'mysql2' ...
I have all dependencies installed and all are 64-bit versions ...
All error are of kind {./client.h:13:
error: redefinition of typedef
‘rb_unblock_function_t’}
Could {#warning rubysig.h is obsolete}
be a reason for this?
Console Capture:
#gem19 install mysql2 -v 0.2.7 -- --with-mysql-dir=/usr/bin --with-mysql-config=/usr/bin/mysql_config --with-mysql-include=/usr/include/mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/bin/ruby19 extconf.rb --with-mysql-dir=/usr/bin --with-mysql-config=/usr/bin/mysql_config --with-mysql-include=/usr/include/mysql
checking for rb_thread_blocking_region()... no
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
gcc -I. -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -mtune=generic -Wall -fno-strict-aliasing -fPIC -Wall -funroll-loops -o result.o -c result.c
In file included from ./client.h:11,
from ./mysql2_ext.h:39,
from result.c:1:
/usr/include/ruby-1.9.1/ruby/backward/rubysig.h:14:2: warning: #warning rubysig.h is obsolete
In file included from ./mysql2_ext.h:39,
from result.c:1:
./client.h:13: error: redefinition of typedef ‘rb_unblock_function_t’
/usr/include/ruby-1.9.1/ruby/intern.h:754: error: previous declaration of ‘rb_unblock_function_t’ was here
./client.h:14: error: redefinition of typedef ‘rb_blocking_function_t’
/usr/include/ruby-1.9.1/ruby/intern.h:755: error: previous declaration of ‘rb_blocking_function_t’ was here
./client.h:20: error: static declaration of ‘rb_thread_blocking_region’ follows non-static declaration
/usr/include/ruby-1.9.1/ruby/intern.h:759: error: previous declaration of ‘rb_thread_blocking_region’ was here
./client.h: In function ‘rb_thread_blocking_region’:
./client.h:23: warning: ‘rb_thread_blocking_region_begin’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/backward/rubysig.h:31)
./client.h:25: warning: ‘rb_thread_blocking_region_end’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/backward/rubysig.h:32)
In file included from ./mysql2_ext.h:39,
from result.c:1:
./client.h:41:7: warning: no newline at end of file
make: *** [result.o] Error 1
This is caused by a patch they introduced on the gem in order for it to run in Ruby 1.8 but it is not needed on Ruby 1.9.
To deactivated this "fix" and be able to install the gem you can define a flag for the compiler:
gem install mysql2 -- --with-cflags=\"-DHAVE_RB_THREAD_BLOCKING_REGION\"
The problem is in the extconf/mkmf section:
rb_thread_blocking_region()... no
But Ruby 1.9.2 defines rb_thread_blocking_region (unless you built Ruby
with some funky set of ifdef's and edits I'm not aware of).
Check your mkmf.log file. It should show you that Ruby failed
to compile/link the conftest.c file that tests for
rb_thread_blocking_region. The reason why is that libcrypt.a
has a dependency on libfreebl3, but the library isn't getting
referenced on the link line.
I fixed the problem by editing /usr/local/lib/ruby/1.9.1/i686-linux/rbconfig.rb like so:
- CONFIG["LIBS"] = "-lpthread -lrt -ldl -lcrypt -lm "
+ CONFIG["LIBS"] = "-lpthread -lrt -ldl -lcrypt -lfreebl3 -lm "
I was able to build the mysql2 gem after. No need to install rvm, etc.
What I did to fix it was to re-install Ruby via RVM. There no more errors after that.
Alternatively, remove the block in client.h that is trying to emulate rb_thread_blocking_region for Ruby 1.8 and you'll be good to go.