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

二次信任 提交于 2019-12-01 11:30:35

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.

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