ytg
ytg

Reputation: 1857

How to pass build flags like `--with-ruby-include` to gem install?

(I know that my Ruby installation is a bit messed up, but:) I'm trying to install a native gem and it gives me an error

ytg@yui:~> sudo /usr/bin/ruby.ruby2.3 /usr/bin/gem install ruby-debug-ide
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-debug-ide:
    ERROR: Failed to build gem native extension.

    current directory: /usr/lib64/ruby/gems/2.3.0/gems/ruby-debug-ide-0.6.0/ext
/usr/bin/ruby.ruby2.3 mkrf_conf.rb
Installing base gem
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
ERROR: Failed to build gem native extension.

    current directory: /usr/lib64/ruby/gems/2.3.0/gems/debase-0.2.2.beta9/ext
/usr/bin/ruby.ruby2.3 -r ./siteconf20161213-12983-1q9o2d7.rb extconf.rb
checking for vm_core.h... no
checking for vm_core.h... no
checking for vm_core.h... no
Makefile creation failed
*************************************************************

  NOTE: If your headers were not found, try passing
        --with-ruby-include=PATH_TO_HEADERS      

*************************************************************

*** 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}/lib64
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/$(RUBY_BASE_NAME).ruby2.3
    --with-ruby-dir
    --without-ruby-dir
    ---with-ruby-include
    --without-ruby-include=${ruby-dir}/include
    --with-ruby-lib
    --without-ruby-lib=${ruby-dir}/lib64

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

  /usr/lib64/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/debase-0.2.2.beta9/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/lib64/ruby/gems/2.3.0/gems/debase-0.2.2.beta9 for inspection.
Results logged to /usr/lib64/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/debase-0.2.2.beta9/gem_make.out
/usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:92:in `run'
  /usr/lib64/ruby/2.3.0/rubygems/ext/ext_conf_builder.rb:37:in `block in build'
  /usr/lib64/ruby/2.3.0/tempfile.rb:295:in `open'
  /usr/lib64/ruby/2.3.0/rubygems/ext/ext_conf_builder.rb:20:in `build'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:164:in `block (2 levels) in build_extension'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:163:in `chdir'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:163:in `block in build_extension'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:162:in `synchronize'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:162:in `build_extension'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:201:in `block in build_extensions'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:198:in `each'
  /usr/lib64/ruby/2.3.0/rubygems/ext/builder.rb:198:in `build_extensions'
  /usr/lib64/ruby/2.3.0/rubygems/installer.rb:742:in `build_extensions'
  /usr/lib64/ruby/2.3.0/rubygems/installer.rb:291:in `install'
  /usr/lib64/ruby/2.3.0/rubygems/request_set.rb:167:in `block in install'
  /usr/lib64/ruby/2.3.0/rubygems/request_set.rb:151:in `each'
  /usr/lib64/ruby/2.3.0/rubygems/request_set.rb:151:in `install'
  /usr/lib64/ruby/2.3.0/rubygems/dependency_installer.rb:405:in `install'
  mkrf_conf.rb:35:in `rescue in <main>'
  mkrf_conf.rb:28:in `<main>'

rake failed, exit code 1

Gem files will remain installed in /usr/lib64/ruby/gems/2.3.0/gems/ruby-debug-ide-0.6.0 for inspection.
Results logged to /usr/lib64/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/ruby-debug-ide-0.6.0/gem_make.out

But then when I try to add the suggested argument, I get:

ytg@yui:~> sudo /usr/bin/ruby.ruby2.3 /usr/bin/gem install ruby-debug-ide --with-ruby-include="/usr/include/ruby-2.3.0/"
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-ruby-include=/usr/include/ruby-2.3.0/
    /usr/lib64/ruby/2.3.0/rubygems/command.rb:378:in `handle_options'
    /usr/lib64/ruby/2.3.0/rubygems/command.rb:299:in `invoke_with_build_args'
    /usr/lib64/ruby/2.3.0/rubygems/command_manager.rb:169:in `process_args'
    /usr/lib64/ruby/2.3.0/rubygems/command_manager.rb:139:in `run'
    /usr/lib64/ruby/2.3.0/rubygems/gem_runner.rb:55:in `run'
    /usr/bin/gem:21:in `<main>'

Is there a way to make gem install recognise those header files?

Upvotes: 3

Views: 3194

Answers (1)

Stefan
Stefan

Reputation: 114158

You have to separate the build flags from the options with --.

From the help page: (gem install --help)

Usage

gem install GEMNAME [GEMNAME ...] [options] -- --build-flags [options]

Later on:

Extension Install Failures

If an extension fails to compile during gem installation the gem specification is not written out, but the gem remains unpacked in the repository. You may need to specify the path to the library’s headers and libraries to continue. You can do this by adding a -- between RubyGems' options and the extension's build options:

$ gem install some_extension_gem
[build fails]
Gem files will remain installed in /path/to/gems/some_extension_gem-1.0 for inspection.
Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out

$ gem install some_extension_gem -- --with-extension-lib=/path/to/lib
[build succeeds]

Upvotes: 7

Related Questions