Nokogiri编译错误 – 找不到库/标题

尝试安装gem,但无法找到标题,尽管指定了它们:

sudo gem install nokogiri -- --with-xml2-lib=/usr/local/lib --with-xml2-include=/usr/local/include/libxml2 --with-xml2-include=/usr/local/include/libxml2 --with-xslt-include=/usr/local/include/libxslt Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /usr/bin/ruby extconf.rb --with-xml2-lib=/usr/local/lib --with-xml2-include=/usr/local/include/libxml2 --with-xml2-include=/usr/local/include/libxml2 --with-xslt-include=/usr/local/include/libxslt checking for #include  ... no ----- libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies. 

/usr/local/include/libxml2/libxml/parser.h文件确实存在,所以我不明白为什么这不起作用。

编辑:我在Centos 5.4上

如果你深入研究/usr/lib/ruby/1.8/mkmf.rb你可以弄清楚如何模拟安装过程中发生的检查。 在我的情况下,我可以通过创建一个名为conftest.c的文件来完成此conftest.c

 #include  

然后尝试运行传递给try_do函数的命令。 在我的情况下,这是:

 gcc -E -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -III/opt/local/include -III/usr/local/include -III/usr/include -III/usr/include -III/usr/include/libxml2 -I/opt/local/include/libxml2 -I/usr/local/include/libxml2 -II/opt/local/include -II/usr/local/include -II/usr/include -II/usr/include -II/usr/include/libxml2 -I/opt/local/include -I/usr/local/include -I/usr/include -I/usr/include -I/usr/include/libxml2 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fPIC -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline conftest.c -o conftest.i 

在我的情况下,我错过了gcc ,这可能不是你所说的,因为你说你从源代码编译。 但希望如果你运行这个命令,它应该让你知道为什么你不能加载libxml2。

如果你对预制的兴趣显然EPEL有一个rubygems-nokogiri包。 很有可能我最终会走这条路。