bundle install问题:缺少mysql.h

时间:2011-05-07 07:33:09

标签: ruby-on-rails-3 bundler mysql2

在我的mac OSX 10.6 32位中,我可以很容易地安装mysql2 gem,但不能在mini mac 10.6 64bit服务器上安装。

我已经在麻烦的服务器中安装了MySQL 5.5.11,而在我的家庭mac MySQL 5.5.0.m2中 不知怎的,当我运行bundle install时,在服务器中它尝试在home mysql2.0.2.6中安装mysql2.0.3.2

请不要告诉我

env ARCHFLAGS =“ - arch x86_64”sudo gem install mysql2 --version'= 0.2.6' - --with-mysql-config = / usr / local / mysql / bin / mysql_config

我试过了,不行。

$ PATH中包含的/ usr / local / mysql / bin也无济于事。

错误代码:

    Installing mysql2 (0.3.2) with native extensions /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.
-----
*** 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
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2 for inspection.
Results logged to /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/ext/mysql2/gem_make.out
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:511:in `block in build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `each'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:159:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/source.rb:96:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:55:in `block in run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:44:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:8:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/cli.rb:225:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/bin/bundle:13:in `<top (required)>'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `load'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `<main>'

13 个答案:

答案 0 :(得分:91)

我尝试了这里发布的所有解决方案,但并不幸运。我用自制软件重新安装了几次mysql但仍然没有运气。然后我遇到了一个带有解决方案的博客文章。

我编辑了/usr/local/Cellar/mysql/5.6.12/bin中的mysql_config文件并将其删除 W编译器选项 -Wno-null-conversion-Wno-unused-private-field 对于cflags和cxxflags。

这解决了gem install mysql2bundle install

的问题

参考:http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

答案 1 :(得分:29)

我在redmine repo上做了一个bundle install并得到了同样的错误信息:

  

缺少mysql.h。请检查你的mysql安装,然后再试一次。

运行Fedora 16 64位,我所做的只是从发行版rpm安装mysql-devel(开发包),问题解决了!

所以我认为你可以

yum install mysql-devel

或apt-get缺少的devel包。

答案 2 :(得分:8)

对于那些没有使用brew来安装mysql并使用mysql 5.6及更高版本的人:

根据this answer

您需要修改mysql_config

在我的案例中放置的/usr/local/mysql-5.6.12-osx10.7-x86_64/bin

并将cflagscxxflags更改为:

cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

经过这次操纵

$ gem install mysql2 -v '0.3.13'

完美无缺

答案 3 :(得分:4)

对我来说好的解决方案是:

$ sudo brew install mysql

$ sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-include=/usr/local/mysql/include

来源:http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard

或者:

$sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-include=/usr/local/mysql/include

如果您的mysql版本是64位

之后我遇到了很多问题,因为如果我想创建数据库:

$: bundle exec rake db:reset

我收到了这个错误:

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Users/workdreamer/Sites/cavortify/implementation/cavortify/mysql/ruby/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Users/workdreamer/Sites/cavortify/implementation/cavortify/mysql/ruby/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
  Expected in: flat namespace

解决方案是:在你的gemfile上添加:gem“ruby-mysql”

好的,一天半找到解决方案。

度过美好的一天!

答案 4 :(得分:2)

此方法适用于64位计算机上的Rails 3.1.0(希望是up)。我在Ruby-1.9.2-p180上使用过。

此博客回答:http://www.tatvartha.com/2010/10/installing-mysql-gem-with-bundler-on-snow-leopard/

基本上,上面的方法:$ sudo env ARCHFLAGS =“ - arch x86_64”gem install mysql - --with-mysql-config = / usr / local / mysql / bin / mysql_config

可能有效,但没有捆绑。

要使用bundler,首先必须在终端上运行:

bundle config build.mysql2 --with-mysql-config=/usr/local/mysql/bin/mysql_config

注意“mysql2”而非“mysql”,如该博客所示。

将配置添加到〜/ .bundle / config文件

然后将其添加到〜/ .bash_profile:

export ARCHFLAGS="-arch x86_64"

告诉bundler在这篇文章的顶部运行命令是一样的。

答案 5 :(得分:1)

我能让这个工作的唯一方法是安装x64版本的mysql。我刚刚使用了位于http://dev.mysql.com/downloads/mysql/的.dmg,它就像一个魅力。希望我能在4小时后得到这个想法。

答案 6 :(得分:1)

这对我的Mac OSX Lion起了作用:

sudo env ARCHFLAGS="-I/usr/local/include/mysql/mysql  -pipe -fPIC    -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/lib/mysql/mysql --with-mysql-include=/usr/local/include/mysql/mysql --with-mysql-config=/usr/local/bin/mysql_config

This blog answered it

答案 7 :(得分:1)

对于mariadb:

sudo apt-get install libmariadbclient18 libmariadbclient-dev

然后

gem install mysql2

可以成功安装。

答案 8 :(得分:0)

验证是否已安装gcc。如果不是,您将收到相同的错误消息。

您可以查看它提到的结果/日志文件,以获取有关原因的更多线索。

答案 9 :(得分:0)

尽我所能发布此内容 - 希望它可以帮助某人并为他们节省大量时间。

我挖了2天的互联网和Stack Overflow,直到我找到this link,然后开始通过this ticket for mysql2,我才真正解决了这个问题。

使用我的设置(如故障单中所述),-Wno-null-conversion -Wno-unused-private-field的编译器开关会中断并给我一个不完全正确的错误,即:< / p>

mysql.h is missing. please check your installation of mysql and try again

答案 10 :(得分:0)

我的问题是首次通过可下载二进制文件安装MySql的结果。它最初安装在5.5.28版本。然后我尝试通过自制软件安装。 Brew安装版本5.6.x.然而,在通过自制软件安装的过程中,/ usr / local / mysql的符号链接仍指向5.5.28。

将符号链接更新为通过自制程序安装的任何版本。

ex:/ usr / local / mysql - &gt; /usr/local/Cellar/mysql/5.6.13 /

这可能只是解决方案的一部分。

答案 11 :(得分:0)

对于Fedora 21上的用户,你已经安装了mysql-devel:

yum install redhat-rpm-config

为我解决了这个问题。看到: redhat docs

答案 12 :(得分:0)

TL;博士:

sudo ln -s /usr/local/opt/mysql@5.6 /usr/local/mysql

我被这个问题难住了将近 2 天,并多次重新安装 xcodemysql

我最初使用 mysql@5.6 安装了 brew,但 bundle install 命令一直失败,因为它找不到 mysql 安装。错误输出如下:

libmysqlclient is missing. You may need to 'brew install mysql' or 'port install mysql', and try again.

但是,使用@Kevin Boedigheimer 的回答有助于解决问题,即我将安装的 mysql@5.6 链接到 /usr/local/mysql

sudo ln -s /usr/local/opt/mysql@5.6 /usr/local/mysql

注意:如果你的 mysql 目录在其他地方,你可以使用:

find / -name 'mysql*5.6' 2&> /dev/null

# '2&> /dev/null' ensures you have just the output you need