Подтвердить что ты не робот

Libxml-ruby: Не удалось создать собственное расширение gem

Я пытаюсь установить libxml-ruby. Я установил libxml2, libxslt и coreutils

Я также прочитал другие сообщения по этой проблеме, но никто не решил это для меня.

brew list libxslt

/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xslt-config
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xsltproc
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libexslt/ (3 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libxslt/ (21 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libexslt.0.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libxslt.1.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/pkgconfig/ (2 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/ (5 other files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/aclocal/libxslt.m4
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/doc/ (90 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/man/ (3 files)

brew list libxml2

/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xml2-config
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmlcatalog
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmllint
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/include/libxml2/ (47 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/libxml2.2.dylib
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/cmake/libxml2/libxml2-config.cmake
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/pkgconfig/libxml-2.0.pc
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/ (3 other files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/aclocal/libxml.m4
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/doc/ (153 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/gtk-doc/ (55 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/man/ (4 files)

gem install libxml-ruby выдает следующую ошибку:

Building native extensions.  This could take a while...
ERROR:  Error installing libxml-ruby:
    ERROR: Failed to build gem native extension.

    current directory: /opt/rubies/2.3.0/lib/ruby/gems/2.3.0/gems/libxml-ruby-2.9.0/ext/libxml
/opt/boxen/rbenv/versions/2.3.0/bin/ruby -r ./siteconf20160630-68248-1qaz7dk.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** 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.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/opt/boxen/rbenv/versions/2.3.0/bin/$(RUBY_BASE_NAME)
    --with-xml2-config
    --without-xml2-config
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
 extconf failure: need libxml2.

    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


To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-14/2.3.0-static/libxml-ruby-2.9.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/libxml-ruby-2.9.0 for inspection.
Results logged to /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-14/2.3.0-static/libxml-ruby-2.9.0/gem_make.out
4b9b3361

Ответ 1

Проблема высокого уровня показана здесь:

checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no

В принципе, установщик говорит вам, что он не может найти libxml/xmlversion.h, но, скорее всего, он скорее всего не сможет найти ваше местоположение libxml2. Он сообщает вам, какие четыре каталога он ищет, поэтому первый шаг - проверить эти каталоги, чтобы увидеть, есть ли libxml2.

Предполагая, что это ни в одном из этих четырех мест, вам нужно его найти. Запустите find / -name xmlversion.h (может потребоваться sudo), чтобы выяснить, где был установлен libxml2. На основе этого ответа Я предполагаю, что ваша проблема в том, что brew установил ее на /usr/local/Cellar/libxml2, но вы должны это подтвердить. После того, как у вас есть место, вы можете вручную указать команду gem install. Что-то вроде этого: (но заполните path/to своим фактическим путем)

gem install libxml-ruby --with-xml2-dir=/path/to/libxml2 --with-xml2-lib=/path/to/libxml2/lib --with-xml2-include=/path/to/libxml2/include

Ответ 2

У меня была аналогичная проблема после того, как я использовал brew для установки libxml2

Brew ссылка решила проблему brew link --force libxml2

Ответ 3

Жизнь после обновления до MacOS Mojave.

xcode-select --install
brew install libxml2
brew link --force libxml2
gem install libxml-ruby -v '2.9.0' -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

В моем примере я установил версию 2.9.0 из библиотеки libxml-ruby. Измените строку версии в соответствии с вашими потребностями. Если доступно, изучите Gemfile.lock чтобы определить, какую версию libxml-ruby Bundler необходимо установить.

Ответ 4

Homebrew:

libxml2 доступен только для бочонков, что означает, что он не был связан с /usr/local, потому что macOS уже предоставляет это программное обеспечение, и параллельная установка другой версии может вызвать все виды проблем.

Итак, нам нужно установить путь к libxml напрямую

brew install libxml2

gem install libxml-ruby \
-- \
--with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"

PS

Если вы получили исключение по последним рубинам:

Просто игнорируй это. Драгоценный камень был успешно установлен. Просто генерация документации Rdoc не удалась.

The internal error was:

        (NoMethodError) undefined method '[]' for nil:NilClass

ERROR:  While executing gem ... (NoMethodError)
    undefined method '[]' for nil:NilClass

Ответ 5

Я также использовал brew для установки libxml2 но мне нужны были следующие параметры:

brew install libxml2 --with-xml2-config
gem install libxml-ruby -- --with-xml2-config=/usr/local/homebrew/opt/libxml2/bin/xml2-config

Ответ 6

MacOS поставляется с установленной libmxl2, всегда не нужно использовать такую утилиту, как brew чтобы сначала установить ее. Однако заголовки находятся не в /usr/include/libxml а в /usr/include/libxml2/libxml.

Сценарий конфигурации gem libxml-ruby пытается определить, установлен ли libxml путем компиляции кода, который выглядит следующим образом:

#include <libxml/xmlversion.h>

Но при компиляции с помощью компилятора, поставляемого с Xcode, будет работать только этот код:

#include <libxml2/libxml/xmlversion.h>

Хитрость заключается в том, чтобы позволить скрипту configure знать, где найти заголовки. В системе MacOS с установленным XCode будет работать следующее:

gem install libxml-ruby -v '3.1.0' -- --with-xml2-include='xcrun --show-sdk-path'/usr/include/libxml2

Ответ 7

Одним из решений является:

cd /Library/Developer/CommandLineTools/Packages/ $ 
open macOS_SDK_headers_for_macOS_10.14.pkg

Принудительная переустановка заголовков для macOS 10.14.