缺少mysql.h …(Ruby on Rails,OSX)

我尝试了几个想法……它们都没有用……我只是想安装mysql2作为gem。 我的mysql正在工作,但每次我的系统说,mysql.h都丢失了……有人有想法吗? 现在非常令人沮丧……

我正在使用osx 10.8.3,ruby 1.9.3,rails 3.2.13和home-brew。

gem install mysql2 -v '0.3.11' Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /Users/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... 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 --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/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby --with-mysql-config --without-mysql-config file `which mysql` /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64 

使用像Homebrew或MacPorts这样的软件包管理器可以很容易地解决这个问题。 直接来自Oracle的MySQL的二进制分发和与OS X本身捆绑的二进制分发没有开发头,其中mysql.h就是其中之一。

Homebrew会修复它:

 brew install mysql 

MacPorts非常相似:

 sudo port install mysql 

这两个安装库,命令行客户端以及库的相关开发头。 启用服务器是可选的。

作为替代方案,您可以直接从Apple获取源代码并以您认为合适的方式安装它。

一般来说,Homebrew是最好的方式。

在Mountain Lion Rails中安装(使用Homebrew和RVM)对我-Wno-null-conversion -Wno-unused-private-field是编辑/usr/local/Cellar/mysql/5.XX.XX/bin/mysql_config并删除-Wno-null-conversion -Wno-unused-private-field来自cxflags和cxflags选项的-Wno-null-conversion -Wno-unused-private-field如下:

之前:

 cflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space! cxxflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space! 

后:

 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安装mysql2继续没有hickups

注意:这可能是由于5.6.10之后引入mysql_config的更改: http ://bugs.mysql.com/bug.php?id = 69645

安装gem有时需要编译源代码。 在这种情况下,MySQL gem需要通过编译C代码来创建ruby接口 – 您很可能需要安装MySQL开发文件。

(之前错过了OSX参考)