libxml-ruby: Failed to build gem native extension

后端 未结 7 1201
逝去的感伤
逝去的感伤 2021-02-07 19:24

I\'m trying to install libxml-ruby. I have installed libxml2, libxslt and coreutils

I have also read other posts rega

相关标签:
7条回答
  • 2021-02-07 20:05

    macOS comes with libmxl2 installed, always, there is no need to use a utility like brew to install it first. Yet the headers are not found in /usr/include/libxml but in /usr/include/libxml2/libxml.

    The configure script of the libxml-ruby gem tries to detect if libxml is installed by compiling code that looks like this:

    #include <libxml/xmlversion.h>

    But when compiling with the compiler shipped with Xcode, only this code would work:

    #include <libxml2/libxml/xmlversion.h>

    The trick is to let the configure script know where to find the headers. On a macOS system with Xcode installed, the following will work:

    gem install libxml-ruby -v '3.1.0' -- --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2
    
    0 讨论(0)
  • 2021-02-07 20:06

    Life after upgrading to 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
    

    In my example I installed version 2.9.0 of the libxml-ruby gem. Change the version string to suit your needs. If available, examine the Gemfile.lock to identify which version of libxml-ruby Bundler is needs to install.

    0 讨论(0)
  • 2021-02-07 20:13

    The high level issue is shown here:

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

    Basically, the installer is telling you it can't find libxml/xmlversion.h but more generally it most likely can't find your libxml2 location. It tells you which four directories it's looking in so the first step is to check those directories to see if libxml2 is there.

    Assuming it's not in any of those four locations, you need to find it. Run find / -name xmlversion.h (might need sudo) to figure out where libxml2 got installed. Based on this answer I'm guessing your issue is that brew installed it to /usr/local/Cellar/libxml2 but you should confirm that. Once you have the location you can manually point your gem install command to it. Something like this: (but fill in path/to with your actual path)

    gem install libxml-ruby --with-xml2-dir=/path/to/libxml2 --with-xml2-lib=/path/to/libxml2/lib --with-xml2-include=/path/to/libxml2/include
    
    0 讨论(0)
  • 2021-02-07 20:17

    I had a similar issue after I had used brew to install libxml2

    Brew link solved the issue brew link --force libxml2

    0 讨论(0)
  • 2021-02-07 20:18

    One solution is to:

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

    To force the reinstallation of the headers for macOS 10.14.

    0 讨论(0)
  • 2021-02-07 20:19

    Homebrew:

    libxml2 is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble.

    So, we need to set libxml path directly

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

    P.S.

    If you get the exception on lastest rubies:

    Just ignore it. The gem was successfully installed. Just the Rdoc documentation generation failed.

    The internal error was:
    
            (NoMethodError) undefined method `[]' for nil:NilClass
    
    ERROR:  While executing gem ... (NoMethodError)
        undefined method `[]' for nil:NilClass
    
    0 讨论(0)
提交回复
热议问题