【问题标题】:compiler error while installing rubygem 'mysql2' in Ruby 1.9.2 over CentOS 64-bit在 CentOS 64 位的 Ruby 1.9.2 中安装 ruby​​gem 'mysql2' 时出现编译器错误
【发布时间】:2011-06-23 11:11:29
【问题描述】:

带有 Ruby 1.8.7 和 1.9.2CentOS 64 位 服务器

{{没有 RVM,需要没有 RVM... 目前所有 Ruby1.9.2 二进制文件都是 ruby​​19 并且可以类似地访问, 所以没有 gem-path 或任何类似的映射}}

安装时出错gem 'mysql2' ...

我已经安装了所有依赖项并且都是64位版本 ...

所有错误都是 {./client.h:13: 错误:重新定义 typedef ‘rb_unblock_function_t’}

可能{#warning ruby​​sig.h 已过时} 是这个原因吗?

控制台捕获:

#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

【问题讨论】:

  • 你安装了 libmysqlclient-dev 吗?
  • libmysqlclient-dev 是 Debian/Ubuntu 机器的 mysql-development 库...对于 CentOS,dev-package 是 mysql-devel 并且我安装了它的 x86_64 版本...实际上我什至尝试过'gem install' 在安装整个 Group Install 开发库包后,可通过 yum for CentOS
  • 我用 'mysql' gem 替换了 'mysql2' gem,它工作正常......所以 Rails3 应用程序现在可以工作了,但原来的问题保持不变......现在,两个 gem有相同的库...仍然'mysql2' gem native-installation 引发错误但'mysql'没有

标签: ruby rubygems compiler-errors centos5 mysql2


【解决方案1】:

这是由他们在 gem 上引入的补丁引起的,以便它在 Ruby 1.8 中运行,但在 Ruby 1.9 上不需要。

要停用此“修复”并能够安装 gem,您可以为编译器定义一个标志:

gem install mysql2 -- --with-cflags=\"-DHAVE_RB_THREAD_BLOCKING_REGION\"

【讨论】:

    【解决方案2】:

    问题出在 extconf/mkmf 部分:

    rb_thread_blocking_region()...没有

    但是 Ruby 1.9.2 定义了 rb_thread_blocking_region(除非你构建了 Ruby 带有一些我不知道的时髦的 ifdef 和编辑)。

    检查您的 mkmf.log 文件。它应该告诉你 Ruby 失败了 编译/链接测试的 conftest.c 文件 rb_thread_blocking_region。原因是 libcrypt.a 依赖于 libfreebl3,但该库没有得到 在链接行上引用。

    我通过编辑 /usr/local/lib/ruby/1.9.1/i686-linux/rbconfig.rb 解决了这个问题,如下所示:

    -  CONFIG["LIBS"] = "-lpthread -lrt -ldl -lcrypt -lm "
    +  CONFIG["LIBS"] = "-lpthread -lrt -ldl -lcrypt -lfreebl3 -lm "
    

    之后我能够构建 mysql2 gem。无需安装rvm等。

    【讨论】:

      【解决方案3】:

      我修复它的方法是通过 RVM 重新安装 Ruby。之后就没有更多错误了。

      或者,删除 client.h 中试图为 Ruby 1.8 模拟 rb_thread_blocking_region 的块,然后您就可以开始了。

      【讨论】:

        猜你喜欢
        • 2011-05-02
        • 2011-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-24
        • 2011-05-06
        相关资源
        最近更新 更多