compiler error while installing rubygem 'mysql2' in Ruby 1.9.2 over CentOS 64-bit

ⅰ亾dé卋堺 提交于 2019-12-01 09:59:22

问题


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

回答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\"



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6453102/compiler-error-while-installing-rubygem-mysql2-in-ruby-1-9-2-over-centos-64-bi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!