Ruby的has_header方法在哪里查找头文件?

时间:2012-06-16 23:42:08

标签: mysql ruby-on-rails rubygems centos header-files

在CentOS 5.7上,我无法安装最新版本的mysql2 gem;它找不到errmsg.h:

/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
checking for mysql_query() in -lmysqlclient... yes
checking for mysql.h... no
checking for mysql/mysql.h... yes
checking for errmsg.h... no
-----
errmsg.h is missing.  please check your installation of mysql and try again.
-----
*** extconf.rb failed ***

mysql头文件存在于/ usr / include / mysql中。服务器上存在较旧版本的gem,因此必须在某一点成功构建。

请注意,它在检查mysql.h时失败,但在mysql / mysql.h上成功。但是,对于errmsg.h,它不会重复此操作。通过这个我猜它不是在看/ usr / include,但我不确定。

我已经挖掘了extconf.rb源代码并发现它正在使用have_header方法来查找头文件。我调试了执行,发现它正在寻找“mysql / errmsg.h”的相对路径。但我没有找到任何解释它如何将其扩展为绝对路径的文档。

哪里& has_header如何找到它的头文件?

1 个答案:

答案 0 :(得分:12)

我相信我找到了答案。

看来have_header查看系统包含路径。如果未设置相关环境变量,则默认包含路径为/usr/local/include/usr/include

如果您想手动设置它们,您可以执行以下操作:

export C_INCLUDE_PATH=/usr/include/mysql/

即使您正在编译C ++程序,如果头文件是C文件,那也是如此。另一方面,如果您的头文件是C ++而不是C,那么您可以这样做:

export CPLUS_INCLUDE_PATH=/usr/include/mysql

当然,您找到了解决办法,即dir_config('mysql')中包含extconf.rb。这使您可以使用--with-mysql-include选项并手动提供路径。

这是我的来源:http://www.network-theory.co.uk/docs/gccintro/gccintro_23.html

这是同一个问题的更一般版本(附答案):How to add a default include path for gcc in linux?