Improve the "Failed to build gem native extension." error message.
@hsbt is already working on this.
Since Oct 28, 2025.
- Dominant language
- Ruby
- Stars
- 4k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 81
Description
Doing a lot of rebuilds on remote builders, this error message is quite unhelpful, misleading and annoying:
$ CONFIGURE_ARGS='--with-cflags='\''-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection'\'' --with-cxxflags='\''-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mcpu=power8 -mtune=power8 -fasynchronous-unwind-tables -fstack-clash-protection'\'' --with-ldflags='\''-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/.package_note-rubygem-hpricot-0.8.6-34.fc36.ppc64le.ld'\'' '
$ gem install -V --local --build-root . --force --document=ri,rdoc hpricot-0.8.6.gem
... snip ...
Building native extensions. This could take a while...
current directory: /builddir/build/BUILD/rubygem-hpricot-0.8.6/usr/share/gems/gems/hpricot-0.8.6/ext/hpricot_scan
["/usr/bin/ruby", "-I", "/usr/share/rubygems", "-r", "./siteconf20220125-118021-hpigkj.rb", "extconf.rb"]
ERROR: Error installing hpricot-0.8.6.gem:
ERROR: Failed to build gem native extension.
current directory: /builddir/build/BUILD/rubygem-hpricot-0.8.6/usr/share/gems/gems/hpricot-0.8.6/ext/hpricot_scan
/usr/bin/ruby -I /usr/share/rubygems -r ./siteconf20220125-118021-hpigkj.rb extconf.rb
Building has failed. See above output for more information on the failure.
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/builddir/build/BUILD/rubygem-hpricot-0.8.6/usr/lib64/gems/ruby/hpricot-0.8.6/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /builddir/build/BUILD/rubygem-hpricot-0.8.6/usr/share/gems/gems/hpricot-0.8.6 for inspection.
Results logged to /builddir/build/BUILD/rubygem-hpricot-0.8.6/usr/lib64/gems/ruby/hpricot-0.8.6/gem_make.out
checking for main() in -lc... *** 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)
--with-hpricot_scan-dir
--without-hpricot_scan-dir
--with-hpricot_scan-include
--without-hpricot_scan-include=${hpricot_scan-dir}/include
--with-hpricot_scan-lib
--without-hpricot_scan-lib=${hpricot_scan-dir}/lib64
--with-c-dir
--without-c-dir
--with-c-include
--without-c-include=${c-dir}/include
--with-c-lib
--without-c-lib=${c-dir}/lib64
--with-clib
--without-clib
/usr/share/ruby/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /usr/share/ruby/mkmf.rb:564:in `try_link0'
from /usr/share/ruby/mkmf.rb:582:in `try_link'
from /usr/share/ruby/mkmf.rb:794:in `try_func'
from /usr/share/ruby/mkmf.rb:1029:in `block in have_library'
from /usr/share/ruby/mkmf.rb:971:in `block in checking_for'
from /usr/share/ruby/mkmf.rb:361:in `block (2 levels) in postpone'
from /usr/share/ruby/mkmf.rb:331:in `open'
from /usr/share/ruby/mkmf.rb:361:in `block in postpone'
from /usr/share/ruby/mkmf.rb:331:in `open'
from /usr/share/ruby/mkmf.rb:357:in `postpone'
from /usr/share/ruby/mkmf.rb:970:in `checking_for'
from /usr/share/ruby/mkmf.rb:1024:in `have_library'
from extconf.rb:7:in `<main>'
While it tries to be useful, it provides just all the wrong information.
From the end, it first says "You have to install development tools first.". That is likely not true, the development tools are there and the chances that something would significantly changed from previous build are small.
Then it provides configuration options, but I don't remember where I'd need to use configuration options. On Fedora build system, the probability that something like this would be the solution is close to zero.
Lastly, it suggests "Check the mkmf.log file for more details.". However, the build done on remote builder, I don't have access to the file. It would be much better if the content was printed there instead.
TL;DR
The smallest improvement would be to include the mkmf.log for failed builds. It might be sometimes longer, but it is never awfully long in my experience.
Should it be too long, the last section of mkmf.log relevant to checking for main() in -lc... would be certainly enough.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.