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

在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,但我不确定。

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

has_header在哪里以及如何定位其头文件?

我相信我找到了答案。

似乎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')中包含dir_config('mysql') 。 这使您可以使用--with-mysql-include选项并手动提供路径。

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

这里是同一个问题的更一般版本(有答案): 如何在linux中为gcc添加默认包含路径?