ruby - 为什么gem安装会忽略PKG_CONFIG_PATH

标签 ruby rubygems pkg-config

我正在尝试安装构建 native 扩展的 libxml-ruby gem。我已将 PKG_CONFIG_PATH 设置为 libxml2 的正确位置并获取 pkg-config 可以看到它:

$ pkg-config --list-all | grep -i xml
libxml-2.0                          libXML - libXML library version2.

不幸的是,gem 构建过程不会:

$ gem install libxml-ruby
...
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** extconf.rb failed ***
...
extconf failure: need libxml2.

虽然路径列表不包含预期的位置:

$ pkg-config --cflags libxml-2.0
-I/usr/local/Cellar/libxml2/2.9.8/include/libxml2

为什么 pkg-config 设置在这里被忽略/如何让 gem build 尊重它?

最佳答案

如果我们看看如何实现 extconf.rb对于 libxml-ruby,它无法在 find_header() 中的预定义位置找到 header 。然而:

Install the library or try one of the following options to extconf.rb:

  --with-xml2-config=/path/to/xml2-config
  --with-xml2-dir=/path/to/libxml2
  --with-xml2-lib=/path/to/libxml2/lib
  --with-xml2-include=/path/to/libxml2/include

尝试:

gem install libxml-ruby -- --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.8 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.8/lib --with-xml2-include=/usr/local/Cellar/libxml2/2.9.8/include/libxml2

因此,对于包安装 - makefile 由 gem 的 extconf.rb 构建。它可以使用 pkg-configdir_config 或两者;对于这个 gem - 它是 dir_config,它是使用命令行选项设置的。

关于ruby - 为什么gem安装会忽略PKG_CONFIG_PATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53807742/

相关文章:

ruby - 将电子邮件注入(inject) Kafka 或任何其他消息队列

static-libraries - 如何使 PKG_CHECK_MODULES 与静态库一起工作?

windows - Vala示例编译错误

ruby - OptionParser 无缘无故地抛出 'Missing Argument'

Ruby 数据格式化

gem - 优胜美地更新后 Sass --watch 中断

mysql - 无法在带有 ruby​​ 版本 2.1.5 的 Windows 8.1 中安装 mysql-2.9.1.gem

linux - 安装 Qt 5.2.1 并使 pkg-config 识别它

ruby-on-rails - Rails 中货币格式的简单方法

mysql - 在 Snow Leopard 上安装 MySQL 和 mysql gem