rubygemfilediscourse

Installing rbtrace 0.4.14 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension


This happened to me several times while trying to install Discourse:

Cannot install rbtrace with native extensions.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

*** 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=/Users/setoelka/.rbenv/versions/2.7.3/bin/$(RUBY_BASE_NAME)
extconf.rb:6:in `sys': make install failed, please report to https://github.com/tmm1/rbtrace/issues (RuntimeError)
    from extconf.rb:43:in `block (2 levels) in <main>'
    from extconf.rb:34:in `chdir'
    from extconf.rb:34:in `block in <main>'
    from extconf.rb:30:in `chdir'
    from extconf.rb:30:in `<main>'

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

  /Users/setoelka/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0/rbtrace-0.4.14/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/setoelka/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/rbtrace-0.4.14 for inspection.
Results logged to /Users/setoelka/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0/rbtrace-0.4.14/gem_make.out

An error occurred while installing rbtrace (0.4.14), and Bundler cannot continue.
Make sure that `gem install rbtrace -v '0.4.14' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rbtrace

Does anyone know about the problem? I tried running:

gem install rbtrace -v '0.4.14' --source 'http://rubygems.org/' -- --with-cflags=-Wno-implicit-function-declaration

No luck so far.


Solution

  • I solved this problem myself by looking at the mkmf.log content.

    TLDR; Use the selected Xcode with standard naming, i.e. Xcode.app.

    It turned out that Ruby would compile the gem using the compiler from the default Xcode. I have multiple versions of Xcodes and use the xcode-select to switch between them.

    The thing is, the ruby setup will always look for the default Xcode.app naming. You'll get this error if you name your selected Xcode something else.