Ruby的has_header方法在哪里寻找头文件? [英] Where does Ruby's have_header method look for header files?
问题描述
在CentOS 5.7框上,我无法安装最新版本的mysql2 gem;它不会找到errmsg.h:
On a CentOS 5.7 box, I'm having trouble installing the newest version of the mysql2 gem; it's not finding 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。
The mysql header files exist at /usr/include/mysql. An older version of the gem exists on the server, so it must have been built successfully at one point.
请注意,它在检查mysql.h时失败,但是,在mysql / mysql.h上成功。但是,它不会对errmsg.h重复此操作。通过这个我猜,它不是看/ usr / include,但我不知道。
Note that it fails on a check for mysql.h, but succeeds on mysql/mysql.h. However, it doesn't repeat this for errmsg.h. By this I'm guessing that it's not looking at /usr/include, but I'm not sure.
我挖掘了extconf.rb源代码,发现它使用 has_header
方法来定位头文件。我调试了执行,发现它正在寻找一个相对路径mysql / errmsg.h。但我没有找到任何解释如何将其扩展成绝对路径的文档。
I've dug into the extconf.rb source code and discovered that it's using the have_header
method to locate the header files. I debugged the execution to find out that it's looking for a relative path of "mysql/errmsg.h". But I haven't found any documentation that explains how it expands that into an absolute path.
has_header如何定位其头文件?
Where & how does have_header locate its header files?
推荐答案
我相信我找到了答案。
看来, have_header
查看系统包含路径。如果没有设置相关的环境变量,默认的包含路径是 / usr / local / include
和 / usr / include
。
It appears that have_header
looks at the system include path. If the relevant environment variables are not set, the default include paths are /usr/local/include
and /usr/include
.
如果你想手动设置,你可以这样做:
If you want to set them manually, you would do something like:
export C_INCLUDE_PATH=/usr/include/mysql/
如果头文件是C文件,则重新编译C ++程序。如果,另一方面,你的头文件是C ++,而不是C,你会这样做:
That's true even if you're compiling a C++ program, if the header file is a C file. If, on the other hand, your header file is C++, not C, you would do:
export CPLUS_INCLUDE_PATH=/usr/include/mysql
当然,你发现了解决方法,在 extconf.rb
中指定c> dir_config('mysql')。这使您可以使用 - with-mysql-include
选项并手动提供路径。
Of course, you found the work-around, which is to include dir_config('mysql')
in your extconf.rb
. That enables you to use the --with-mysql-include
option and supply the path manually.
来源: http://www.network-theory.co.uk/docs/gccintro/gccintro_23。 html
这里是同一个问题的一个更一般的版本(有答案):如何在linux中为gcc添加默认包含路径?
And here's a more general version of the same question (with answers): How to add a default include path for gcc in linux?
这篇关于Ruby的has_header方法在哪里寻找头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!