本文介绍了如何使用mkmf.log安装Nokogiri Ruby gem,并说libiconv未找到?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何诊断并解决这个问题?

 #gem install nokogiri 
构建原生扩展。这可能需要一段时间...
错误:安装nokogiri时出错:
错误:无法构建gem本机扩展。
...
/opt/ruby/1.9.3-p194/bin/ruby extconf.rb
检查libxml / parser.h ... *** extconf.rb失败* **
由于某些原因无法创建Makefile,可能缺少
必需的库和/或标题。查看mkmf.log文件以获取更多
的详细信息。您可能需要配置选项。
...
/opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in`try_do':
编译器无法生成一个可执行文件。 (RuntimeError)
您必须先安装开发工具。
from /opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in`try_cpp'
...

$


$ b

例如:

为了找出失败的内容,请转到您的ruby gems目录。

pre> $ cd< MY RUBY DIRECTORY> /lib/ruby/gems/2.0.0/gems

如果您不知道您的gem目录,请尝试以下操作:

  $ echo $ GEM_HOME 
/opt/gems/2.0.0
$ cd /opt/gems/2.0.0/gems

我正在安装什么版本的nokogiri?

  $ ls -ladg nokogiri- * 
nokogiri-1.5.5

转到安装目录:

  $ cd nokogiri-1.5.5 / ext / nokogiri 

尝试手动安装:

  $ ruby​​ extconf.rb 

结果:

 检查libxml / parser.h ... *** extconf.rb失败*** 
...



我使用的是Ubuntu,因此我搜索了任何类似的包:

  $ aptitude search libxml 

结果:

  p libxml2  -  GNOME XML库
p libxml2-dev - GNOME XML库的开发文件
...

我相信libxml2会正常工作。

  $ apt-get install libxml2 

Ruby本地宝石通常需要* -dev包头文件安装它们:

  $ apt-get install libxml2-dev 

现在有解析器文件吗?

  $ find / | grep libxml / parser.h 

是的,结果显示解析器:

  /usr/include/libxml2/libxml/parser.h 

现在尝试再次安装,这次提供libxml2路径:
$ b $ pre $ $ $ $ $ gem install nokogiri - --with-xml2-dir = / usr / include / libxml2

它仍然失败,所以请阅读mkmf错误日志:

  $ more mkmf.log 

错误日志显示失败的结果,并且这些行看起来很有希望:

 没有找到libxslt的软件包配置

是否有包装?

  $ aptitude search libxslt 

结果:

  v libxslt-dev 
i libxslt-ruby
...
code>

安装开发包:

  $ apt-get install libxslt-dev 

现在尝试再次安装,并将xslt放在路径上:

 $ gem install nokogiri  -  \ 
--with-xml2-dir = / usr / include / libxml2 \
--with-xslt-dir = / usr / include / libxslt

成功!


I'm installing the Ruby Nokogiri gem and finding the error below.

How to diagnose this and solve it?

# gem install nokogiri
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.
...
/opt/ruby/1.9.3-p194/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
...
/opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do':
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
...
解决方案

To diagnose and solve, here's what worked for me.

To find out what failed, go to your ruby gems directory.

For example:

$ cd <MY RUBY DIRECTORY>/lib/ruby/gems/2.0.0/gems

If you don't know your gem directory, try this:

$ echo $GEM_HOME
/opt/gems/2.0.0
$ cd /opt/gems/2.0.0/gems

What version of nokogiri am I installing?

$ ls -ladg nokogiri-*
nokogiri-1.5.5

Go to the installer directory:

$ cd nokogiri-1.5.5/ext/nokogiri

Try installing manually:

$ ruby extconf.rb

Result:

checking for libxml/parser.h... *** extconf.rb failed ***
...

I'm using Ubuntu so I search for any similar packages:

$ aptitude search libxml

Results:

p libxml2 - GNOME XML library
p libxml2-dev - Development files for the GNOME XML library
...

I believe that libxml2 will work fine.

$ apt-get install libxml2

Ruby native gems often need the *-dev packages for headers so install them:

$ apt-get install libxml2-dev

Now do I have the parser file?

$ find / | grep libxml/parser.h

Yes, the result shows the parser:

/usr/include/libxml2/libxml/parser.h

Now try installing again, this time providing the libxml2 path:

$ gem install nokogiri -- --with-xml2-dir=/usr/include/libxml2

It still fails, so read the mkmf error log:

$ more mkmf.log

The error log shows what failed and has these lines that look promising:

package configuration for libxslt is not found

Is there a package for it?

$ aptitude search libxslt

Results:

v   libxslt-dev
i   libxslt-ruby
...

Install the dev package:

$ apt-get install libxslt-dev

Now try installing again, and also put xslt on the path:

$ gem install nokogiri -- \
--with-xml2-dir=/usr/include/libxml2 \
--with-xslt-dir=/usr/include/libxslt

Success!

这篇关于如何使用mkmf.log安装Nokogiri Ruby gem,并说libiconv未找到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:21