问题描述
在 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.服务器上存在较旧版本的 gem,因此它一定是在某一时刻成功构建的.
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 源代码,发现它使用 have_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.
在哪里&have_header 是如何定位其头文件的?
Where & how does have_header locate its header files?
推荐答案
我相信我已经找到了答案.
I believe I've found an answer.
似乎 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
中包含 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 的 have_header 方法在哪里查找头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!