繁体   English   中英

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

[英]mysql.h is missing … (Ruby on Rails, OSX)

我尝试了几个想法......他们都没有工作......我只是想将mysql2安装为gem。 我的 mysql 正在运行,但是每次我的系统都说缺少 mysql.h ......有人有想法吗? 现在很郁闷。。。

我正在使用 osx 10.8.3、ruby 1.9.3、rails 3.2.13 和自制软件。

    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

在 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 install mysql2 继续进行,没有问题

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

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

Homebrew 会像这样修复它:

brew install mysql

MacPorts 非常相似:

sudo port install mysql

这两个都安装库、命令行客户端和库的相关开发头文件。 启用服务器是可选的。

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

通常 Homebrew 是最好的方法。

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

(之前错过了 OSX 参考)

您需要安装 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

如果您使用的是标准 XAMPP,这可能是问题所在,您可能需要安装 xampp-devel,它是 xampp 的开发包,该发行版包含 mysql 头文件*.h文件以及其他相关资源,您可以找到旧版本在这里

您可以复制/Applications/XAMPP/xamppfilesinclude目录,然后使用以下命令安装 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

这个版本对我mysql_config ,如果您指定mysql_config路径,则不需要包含--with-mysql-dir ,然后您应该得到类似的输出:

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

不要忘记更新捆绑包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM