我试图让 Ruby gem "Nokogiri" 在我没有 root 权限的 Solaris 机器上运行。到目前为止我所做的:
- 我已经在我的主目录中构建了自己的 ruby 版本(1.9.2p180)
- 尝试使用“gem install nokogiri”安装 nokogiri
gem install 然后抛出这个错误:
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/home/bender/ruby/bin/ruby extconf.rb
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
所以我在 /home/myuser/work/libiconv 下载并构建了 libiconv
$ ls /home/myuser/work/libiconv/
bin build include lib share
并将位置作为 nokogiri 的参数传递:
gem install nokogiri -- --with-iconv-dir=/home/myuser/work/libiconv --with-iconv-include=/home/myuser/work/libiconv/include --with-iconv-lib=/home/myuser/work/libiconv/lib
现在 gem 构建并且没有显示错误。问题是,当我现在尝试使用它时,例如在 irb 中,它以某种方式无法加载:
require 'nokogiri'
LoadError: ld.so.1: ruby: fatal: libiconv.so.2: open failed: No such file or directory - /home/myuser/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.so
from /home/myuser/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/myuser/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/myuser/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.4/lib/nokogiri.rb:13:in `<top (required)>'
from /home/myuser/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:57:in `require'
from /home/myuser/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:57:in `rescue in require'
from /home/myuser/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from (irb):1
from /home/myuser/ruby/bin/irb:12:in `<main>'
但是当我寻找应该丢失的文件时,它就在那里并且可读/可执行:
ll /home/myuser/ruby/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.4/lib/nokogiri/
total 66
...
-rwxr-xr-x 1 myuser group 370552 Jun 6 22:53 nokogiri.so
...
好的,这就是我卡住的地方..文件在那里但无法打开?我试图重建没有效果的 libiconv。Nokogiri 不会抛出构建过程失败的任何错误。所以我不知道如何解决这个问题,谷歌也无法给我答案。我希望这里有人能给我一些提示。
/编辑
我用谷歌搜索了更多,发现有人使用 ldd 来显示依赖关系的这篇文章。当我对 nokogiri 做同样的事情时,它说:
ldd /home/myuser/ruby/bin/nokogiri
ldd: /home/myuser/ruby/bin/nokogiri: unsupported or unknown file type
我想这是因为它是一个 ruby 文件,但如果它是相关的,我想提一下。