gpt4 book ai didi

mysql - Ruby 的 have_header 方法在哪里寻找头文件?

转载 作者:可可西里 更新时间:2023-11-01 06:59:00 24 4
gpt4 key购买 nike

在 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”的相对路径。但我还没有找到任何文档来解释它如何将其扩展为绝对路径。

have_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

当然,您找到了解决方法,即在您的 extconf.rb 中包含 dir_config('mysql')。这使您能够使用 --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?

关于mysql - Ruby 的 have_header 方法在哪里寻找头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11067877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com