tags:

views:

230

answers:

1

I want to install a ruby gem which tries to build a native extension. The gem in this case is nokogiri. If I do gem install nokogiri, the native extension dynamically links against libxml, libxslt libs. I want to statically link against those libs. How should I go about this?

A: 

Here are some pointers, but's it's not easy unless nokogiri contains build flags to support it:

  1. If nokogiri supports it, you can pass build arguments to install gem like this

    gem install nokogiri -- --with-static-libxml
    
  2. If there is no built in support you can try tweaking linkflags used to install the gem with:

    gem install nokogiri -- --with-ldflags='-static'
    

    It's likely that the build will fail, since --with-ldflags overrides all LDFLAGS, and also '-static' tries to link everything as static, so you need to examine mkmf.log, and treat it accordingly.

  3. If you want to do it manually, one way to do it is making the gem install fail by invoking with invalid option like:

    gem install nokogiri -- --with-ldflags
    

    This will cause the installation to fail with a message like this:

    Building native extensions.  This could take a while...
    ERROR:  Error installing nokogiri:
           ERROR: Failed to build gem native extension.
    
    
    ruby extconf.rb --with-ldflags
    

    So you should be able to build the gem yourself then after it's done finish the installation with (see gem help install):

      gem spec ../../cache/nokogiri-1.4.1.gem --ruby > \
             ../../specifications/nokogiri-1.4.1.gemspec
    
mfazekas
Is there any way I can dowonload the package (gem fetch), then unpack it and modify the Makefile and then install it?
@ajstack, yes, that should be possible see gem help install, i've added it to my answer
mfazekas