title: Gem::Ext::BuildError: ERROR: Failed to build gem native extension on macOS Monterey
body: <p>When I run <code>bundle install</code> on my rails 5 project, I am getting a number of errors on gems that appear to have native extensions. Here is the top of the output for one of those gems:</p>
  <pre><code>Installing nio4r 1.2.1 with native extensions
  
  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  
  checking for unistd.h... yes
  checking for rb_thread_blocking_region()... no
  checking for rb_thread_call_without_gvl()... yes
  checking for sys/select.h... yes
  checking for poll.h... yes
  checking for sys/epoll.h... no
  checking for sys/event.h... yes
  checking for sys/queue.h... yes
  checking for port.h... no
  checking for sys/resource.h... yes
  creating Makefile
  
  current directory: /Users/&lt;my-username&gt;/.rvm/gems/ruby-2.7.4/gems/nio4r-1.2.1/ext/nio4r
  make &quot;DESTDIR=&quot; clean
  
  current directory: /Users/&lt;my-username&gt;/.rvm/gems/ruby-2.7.4/gems/nio4r-1.2.1/ext/nio4r
  make &quot;DESTDIR=&quot;
  compiling monitor.c
  monitor.c:91:24: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
  if(interests_id == rb_intern(&quot;r&quot;)) {
                     ^~~~~~~~~~~~~~
  /Users/&lt;my-username&gt;/.rvm/rubies/ruby-2.7.4/include/ruby-2.7.0/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
      __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                    ^
  monitor.c:91:24: note: '{' token is here
      if(interests_id == rb_intern(&quot;r&quot;)) {
                         ^~~~~~~~~~~~~~
  </code></pre>
  <p>I have tried a number of things.</p>
  <p>Per <a href="https://stackoverflow.com/questions/42652189/how-to-fix-a-bundle-install-nio4r-error-on-rails-5-0-0">this post</a> I tried the following suggestions:</p>
  <pre><code># didn't fix it
  bundle config build.nio4r --with-cflags=&quot;-std=c99&quot;
  bundle
  
  # didn't fix it
  xcode-select --install
  sudo xcodebuild -license accept
  bundle
  </code></pre>
  <p>I also referenced <a href="https://gorails.com/setup/osx/12-monterey" rel="nofollow noreferrer">this Go Rails guide</a>, specifically the &quot;Final Steps&quot; section that deals with gems that require C extensions, but that command seems to not apply because I didn't migrate my macOS from Mojave.</p>
  <p>At this point I'm not sure what to try next. Ultimately: it appears the issue revolves around being unable to install gems that require C extensions.</p>
  <p>Environment:</p>
  <ul>
  <li>macOS Monterey version <code>12.2</code></li>
  <li>Using rvm with ruby version <code>2.7.4</code></li>
  <li>Project is using rails version <code>5.0.1</code></li>
  </ul>