Rails 3.2.3 MySQL 5.5.1 Mysql2 gem安装失败,ld不兼容

时间:2012-05-17 11:34:23

标签: mysql ruby-on-rails-3 gem ubuntu-11.04 mysql2

我有一个干净的构建系统,如下所示

Ubuntu 11.04

Rvm 1.13.5

Ruby 1.9.3p194

Rails 3.2.3

宝石1.8.24

MySql 5.5.24-1(安装在/ usr / local中)

我正在尝试安装mysql2 gem(0.3.11)并遇到以下问题:

 pal@smurf01:~$ sudo gem install mysql2
   [sudo] password for pal: 
   Building native extensions.  This could take a while...
   ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

        /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
   checking for rb_thread_blocking_region()... yes
   checking for rb_wait_for_single_fd()... yes
   checking for mysql.h... yes
   checking for errmsg.h... yes
   checking for mysqld_error.h... yes
   creating Makefile

   make
   compiling client.c
   client.c: In function 'rb_raise_mysql2_error':
   client.c:98:3: warning: ISO C90 forbids mixed declarations and code
   client.c: In function 'rb_mysql_client_socket':
   client.c:590:3: warning: ISO C90 forbids mixed declarations and code
   compiling mysql2_ext.c
   compiling result.c
   linking shared-object mysql2/mysql2.so
   /usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.so when searching for -lmysqlclient_r
   /usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.a when searching for -lmysqlclient_r
   /usr/bin/ld: cannot find -lmysqlclient_r
   collect2: ld returned 1 exit status
   make: *** [mysql2.so] Error 1


   Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
   Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
 pal@smurf01:~$

第一个问题:有没有人在Ubuntu上使用MySql 5.5.1运行Rails mysql2?我让它在5.1的另一个系统上运行。宝石描述在支持的MySql版本上含糊不清。

第二个问题:有没有人遇到过这个问题?在过去一年左右的时间里,我已经与mysql2 gem争夺了各种库问题,但这似乎有所不同。

感谢任何帮助。

BTW:恢复到MySql 5.1是一个有效的解决方案!

问候

彼得

4 个答案:

答案 0 :(得分:14)

或仅apt-get install libmysqlclient-dev然后gem install mysql2

答案 1 :(得分:2)

所以问题似乎是缺少库和一些链接。执行以下操作解决了这个问题。

获取新的并安装由Nathan Rennie Waldock友情提供的libmysqlclient-dev deb软件包

 wget http://ppa.launchpad.net/nathan-renniewaldock/ppa/ubuntu/pool/main/m/mysql-5.5/libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb./;l
 dpkg -i libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb

然后创建一些mysql2需要的链接,因为它似乎无法遵循mysql路径

cd /usr/lib/
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.a .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18 .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18.0.0 .

现在快乐地安装mysql2 gem

sudo gem install mysql2
  Fetching: mysql2-0.3.11.gem (100%)
  Building native extensions.  This could take a while...
  Successfully installed mysql2-0.3.11
  1 gem installed
  Installing ri documentation for mysq2l-0.3.11...
  Installing RDoc documentation for mysql2-0.3.11...

答案 2 :(得分:0)

Ubuntu 12.04中的同一问题也使用了接受的答案中提到的ppa。 但是我的系统上也没有名称为_r的libmysqlclient文件。 谷歌搜索我发现包构建器已经开始从文件中删除_r后缀,因此可能发生在11.10和12.04之间。

此外路径与前面提到的路径有点不同所以这些是我必须创建的符号链接:

ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.a ./libmysqlclient_r.a
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so ./libmysqlclient_r.so
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 ./libmysqlclient_r.so.18
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0 ./libmysqlclient_r.so.18.0.0

答案 3 :(得分:0)

我也有这个问题......

我做dpkg -r mysql-devel就像我试图做的那样apt-get install libmysqlclient-dev我说错了:

  

解压缩libmysqlclient-dev(来自... / libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb)... dpkg:   错误处理   /var/cache/apt/archives/libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb   (--unpack):试图覆盖'/ usr / bin / mysql_config',这是   也在包mysql-devel 5.5.28-2

执行此操作后,gem install mysql2正常工作! yay:)