我尝试了几个想法......它们都没有奏效...... 我只是想安装mysql2作为宝石。我的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
答案 0 :(得分:46)
在Mountain Lion Rails安装(使用Homebrew和RVM)中对我有用的是编辑/usr/local/Cellar/mysql/5.XX.XX/bin/mysql_config
并从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 install mysql2继续进行,没有hickups
注意:这可能是由于5.6.10之后引入mysql_config的更改:http://bugs.mysql.com/bug.php?id=69645
答案 1 :(得分:4)
使用像Homebrew或MacPorts这样的包管理器可以很容易地解决这个问题。直接来自Oracle的MySQL和与OS X本身捆绑的二进制分发没有开发头,其中mysql.h
就是其中之一。
Homebrew会解决这个问题:
brew install mysql
MacPorts非常相似:
sudo port install mysql
这两个安装库,命令行客户端以及库的相关开发标头。启用服务器是可选的。
作为替代方案,您可以获取源direct from Apple并以您认为合适的方式安装它。
一般来说,Homebrew是最好的方式。
答案 2 :(得分:0)
安装gem有时会涉及编译源代码。在这种情况下,MySQL gem需要通过编译C代码来创建ruby接口 - 您很可能需要安装MySQL开发文件。
(错过了之前的OSX参考资料)
答案 3 :(得分:0)
您需要安装mysql的开发头文件,使用brew可能需要安装低于8的版本,因为已从此发行版中删除了一些头文件。例如,my_global.h
已删除,因此,如果您的代码使用此标头,则系统将强制您安装8之前的版本。
头文件依赖项
我们已经开始清理头文件的依赖项,即 “包括您使用的内容”以及重新组织头文件以将其删除 建立依赖关系。我们修复了模糊的包含路径;差不多所有 现在应该从根开始。增量增加了很多 例如my_global.h消失了,sql_class.h也减少了 一点点的重量。随附的客户标头是自包含的,甚至更多 理智的例如,客户端标头现在独立于平台(否 32位和64位Linux之间的差异)。
brew install mysql@5.7 mysql-client@5.7
答案 4 :(得分:0)
如果您使用的是标准XAMPP,则可能是问题所在,您可能需要安装xampp-devel,它是xampp的开发包,该发行版包含mysql头文件*.h
以及其他相关文件来源,您可以在here中找到较旧的版本。
然后您可以复制include
中的/Applications/XAMPP/xamppfiles
目录,然后使用以下命令安装gem:
sudo gem install mysql2 -v 0.3.21 -- --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config --with-mysql-include=/Applications/XAMPP/xamppfiles/lib/include/ --no-ri --no-rdoc
此版本对我有用,如果您指定了 --with-mysql-dir
路径,则无需包含mysql_config
,那么您应该获得类似的输出:
This could take a while...
Successfully installed mysql2-0.3.21
Parsing documentation for mysql2-0.3.21
Installing ri documentation for mysql2-0.3.21
Done installing documentation for mysql2 after 0 seconds
1 gem installed
您可能还需要为rails提供正确版本的libmysqlclient
,这是使用Symlink的示例:
sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
请不要忘记更新捆绑包。