ERROR: Failed to build gem native extension

How should I fix this error?

Mac Apple M2 (MacOS 15.0)
I install Ruby through homebrew

which ruby # /opt/homebrew/opt/ruby/bin/ruby
ruby -v # ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin24]

which /opt/homebrew/opt/ruby/bin/gem
gem -v # 3.5.20
(base) loctran@Locs-MacBook-Air ~ % gem install jekyll --user-install

Building native extensions. This could take a while...

ERROR: Error installing jekyll:

ERROR: Failed to build gem native extension.

current directory: /Users/loctran/.gem/ruby/3.3.0/gems/eventmachine-1.2.7/ext

/opt/homebrew/opt/ruby/bin/ruby extconf.rb

checking for pkg-config for openssl... ["-I/opt/homebrew/Cellar/openssl@3/3.3.2/include ", "-L/opt/homebrew/Cellar/openssl@3/3.3.2/lib", "-lssl -lcrypto"]

-----

Using OpenSSL from pkg-config -I/opt/homebrew/Cellar/openssl@3/3.3.2/include && -L/opt/homebrew/Cellar/openssl@3/3.3.2/lib && -lssl -lcrypto

-----

checking for -lcrypto... yes

checking for -lssl... yes

checking for openssl/ssl.h... yes

checking for openssl/err.h... yes

checking for rb_trap_immediate in ruby.h,rubysig.h... no

checking for rb_thread_blocking_region()... no

checking for rb_thread_call_without_gvl() in ruby/thread.h... yes

checking for rb_thread_fd_select()... yes

checking for rb_fdset_t in ruby/intern.h... yes

checking for rb_wait_for_single_fd()... yes

checking for rb_enable_interrupt()... no

checking for rb_time_new()... yes

checking for inotify_init() in sys/inotify.h... no

checking for __NR_inotify_init in sys/syscall.h... no

checking for writev() in sys/uio.h... yes

checking for pipe2() in unistd.h... no

checking for accept4() in sys/socket.h... no

checking for SOCK_CLOEXEC in sys/socket.h... no

checking for sys/event.h... yes

checking for sys/queue.h... yes

checking for clock_gettime()... yes

checking for CLOCK_MONOTONIC_RAW in time.h... yes

checking for CLOCK_MONOTONIC in time.h... yes

CXXFLAGS=-fdeclspec

creating Makefile

current directory: /Users/loctran/.gem/ruby/3.3.0/gems/eventmachine-1.2.7/ext

make DESTDIR\= sitearchdir\=./.gem.20240928-67391-p565vt sitelibdir\=./.gem.20240928-67391-p565vt clean

current directory: /Users/loctran/.gem/ruby/3.3.0/gems/eventmachine-1.2.7/ext

make DESTDIR\= sitearchdir\=./.gem.20240928-67391-p565vt sitelibdir\=./.gem.20240928-67391-p565vt

compiling binder.cpp

In file included from binder.cpp:20:

./project.h:25:10: fatal error: 'iostream' file not found

25 | #include <iostream>

| ^~~~~~~~~~

1 error generated.

make: *** [binder.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/loctran/.gem/ruby/3.3.0/gems/eventmachine-1.2.7 for inspection.

Results logged to /Users/loctran/.gem/ruby/3.3.0/extensions/arm64-darwin-24/3.3.0/eventmachine-1.2.7/gem_make.out

You might try installing without --user-install? With Homebrew, you don’t need root access to install Gems, so no need for user dir installs.

I am also getting errors related to iostream.h and I didn’t use --user-install.

% ruby -v
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin24]
% gem -v
3.5.20

MacOS Sequoia 15.0

This has only started happening since upgrading to MacOS 15.0

I normally do a monthly upgrade/update on vairous things including packages installed via homebrew, gems, and various things.

My process is:

  1. brew update
  2. brew upgrade
  3. gem update
  4. Change into the path for the site I want to update
  5. bundle update --bundler
  6. bundle update --all

It was at step 5 (bundle update --bundler) that I got this error:

% bundle update --bundler
Fetching gem metadata from https://rubygems.org/.
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Installing strscan 3.1.0 with native extensions
Installing http_parser.rb 0.8.0 with native extensions
Installing eventmachine 1.2.7 with native extensions
Installing sassc 2.4.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/eventmachine-1.2.7/ext
/opt/homebrew/opt/ruby/bin/ruby extconf.rb
checking for pkg-config for openssl... ["-I/opt/homebrew/Cellar/openssl@3/3.3.2/include ", "-L/opt/homebrew/Cellar/openssl@3/3.3.2/lib", "-lssl -lcrypto"]
-----
Using OpenSSL from pkg-config -I/opt/homebrew/Cellar/openssl@3/3.3.2/include  && -L/opt/homebrew/Cellar/openssl@3/3.3.2/lib && -lssl -lcrypto
-----
checking for -lcrypto... yes
checking for -lssl... yes
checking for openssl/ssl.h... yes
checking for openssl/err.h... yes
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_fd_select()... yes
checking for rb_fdset_t in ruby/intern.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for pipe2() in unistd.h... no
checking for accept4() in sys/socket.h... no
checking for SOCK_CLOEXEC in sys/socket.h... no
checking for sys/event.h... yes
checking for sys/queue.h... yes
checking for clock_gettime()... yes
checking for CLOCK_MONOTONIC_RAW in time.h... yes
checking for CLOCK_MONOTONIC in time.h... yes
CXXFLAGS=-fdeclspec
creating Makefile

current directory: /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/eventmachine-1.2.7/ext
make DESTDIR\= sitearchdir\=./.gem.20240930-1891-jwpvzw sitelibdir\=./.gem.20240930-1891-jwpvzw clean

current directory: /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/eventmachine-1.2.7/ext
make DESTDIR\= sitearchdir\=./.gem.20240930-1891-jwpvzw sitelibdir\=./.gem.20240930-1891-jwpvzw
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:25:10: fatal error: 'iostream' file not found
   25 | #include <iostream>
      |          ^~~~~~~~~~
1 error generated.
make: *** [binder.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/eventmachine-1.2.7 for inspection.
Results logged to /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/extensions/arm64-darwin-24/3.3.0/eventmachine-1.2.7/gem_make.out

  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:125:in `run'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:51:in `block in make'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `each'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `make'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:193:in `build_extension'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `each'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `build_extensions'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/installer.rb:853:in `build_extensions'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/rubygems_gem_installer.rb:109:in `build_extensions'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/source/rubygems.rb:205:in `install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/gem_installer.rb:55:in `install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/gem_installer.rb:17:in `install_from_spec'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/parallel_installer.rb:133:in `do_install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/parallel_installer.rb:124:in `block in worker_pool'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:62:in `apply_func'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:57:in `block in process_queue'
  <internal:kernel>:187:in `loop'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:54:in `process_queue'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing eventmachine (1.2.7), and Bundler cannot continue.

In Gemfile:
  jekyll-feed was resolved to 0.15.1, which depends on
    jekyll was resolved to 4.2.2, which depends on
      em-websocket was resolved to 0.5.3, which depends on
        eventmachine


Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/ext
/opt/homebrew/opt/ruby/bin/ruby extconf.rb
creating Makefile

current directory: /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/ext
make DESTDIR\= sitearchdir\=./.gem.20240930-1891-el47b sitelibdir\=./.gem.20240930-1891-el47b clean

current directory: /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/ext
make DESTDIR\= sitearchdir\=./.gem.20240930-1891-el47b sitelibdir\=./.gem.20240930-1891-el47b
compiling ./libsass/src/ast.cpp
In file included from ./libsass/src/ast.cpp:3:
In file included from ./libsass/src/sass.hpp:55:
In file included from ./libsass/src/memory.hpp:8:
./libsass/src/memory/allocator.hpp:8:10: fatal error: 'vector' file not found
    8 | #include <vector>
      |          ^~~~~~~~
1 error generated.
make: *** [ast.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0 for inspection.
Results logged to /Users/dan/Sites/example.com/repository.git/source/vendor/bundle/ruby/3.3.0/extensions/arm64-darwin-24/3.3.0/sassc-2.4.0/gem_make.out

  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:125:in `run'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:51:in `block in make'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `each'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:43:in `make'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:193:in `build_extension'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `each'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `build_extensions'
  /opt/homebrew/Cellar/ruby/3.3.5/lib/ruby/3.3.0/rubygems/installer.rb:853:in `build_extensions'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/rubygems_gem_installer.rb:109:in `build_extensions'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/source/rubygems.rb:205:in `install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/gem_installer.rb:55:in `install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/gem_installer.rb:17:in `install_from_spec'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/parallel_installer.rb:133:in `do_install'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/installer/parallel_installer.rb:124:in `block in worker_pool'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:62:in `apply_func'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:57:in `block in process_queue'
  <internal:kernel>:187:in `loop'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:54:in `process_queue'
  /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.20/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing sassc (2.4.0), and Bundler cannot continue.

In Gemfile:
  jekyll-feed was resolved to 0.15.1, which depends on
    jekyll was resolved to 4.2.2, which depends on
      jekyll-sass-converter was resolved to 2.2.0, which depends on
        sassc
dan@Copper source % bundle update --all
/opt/homebrew/opt/ruby/bin/bundle:25:in `load': cannot load such file -- /opt/homebrew/lib/ruby/gems/3.3.0/gems/bundler-2.5.18/exe/bundle (LoadError)
	from /opt/homebrew/opt/ruby/bin/bundle:25:in `<main>'

I fixed this by uninstalling and reinstalling xcode command line tools after googling for similar issues related to iostream:

Thank you @chuckhoupt @danieldurrans
I gave up installing it on my mac. I switch into using docker container and follow this link. It turns out ok

This thread saved my day. Thank you for sharing the information!

1 Like