我正在尝试安装构建 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-config 或 dir_config 或两者;对于这个 gem - 它是 dir_config,它是使用命令行选项设置的。
关于ruby - 为什么gem安装会忽略PKG_CONFIG_PATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53807742/