MacOS 10.14 was released recently and updating the operating system of your development environment can be scary. Typically, I'll wait some time before I update to ensure I don't lose productivity. I took the plunge and updated and ran into a strange error where a library was missing.

If you've upgrade to Mojave and try to install a gem like mini_racer you will run into problems with a library not being found. This was due to XCode 10 removing the library. However, there is an easy fix to this.

The first indication was that the command line tools were not installed.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/kobaltz/.rvm/gems/ruby-2.4.4/gems/mini_racer-0.1.14/ext/mini_racer_extension /Users/kobaltz/.rvm/rubies/ruby-2.4.4/bin/ruby -r ./siteconf20180928-7580-5rhj67.rb extconf.rb checking for -lpthread... *** 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 --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/kobaltz/.rvm/rubies/ruby-2.4.4/bin/$(RUBY_BASE_NAME) --with-pthreadlib --without-pthreadlib /Users/kobaltz/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/mkmf.rb:457:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.

Make sure XCode Command Line Tools is installed

xcode-select --install

So then the everything should work correctly..., not quite. Installing mini_racer still failed.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/kobaltz/.rvm/gems/ruby-2.4.4/gems/mini_racer-0.1.14/ext/mini_racer_extension /Users/kobaltz/.rvm/rubies/ruby-2.4.4/bin/ruby -r ./siteconf20180928-8233-1xwbzpf.rb extconf.rb checking for -lpthread... yes checking for -lobjc... yes creating Makefile current directory: /Users/kobaltz/.rvm/gems/ruby-2.4.4/gems/mini_racer-0.1.14/ext/mini_racer_extension make "DESTDIR=" clean current directory: /Users/kobaltz/.rvm/gems/ruby-2.4.4/gems/mini_racer-0.1.14/ext/mini_racer_extension make "DESTDIR=" compiling mini_racer_extension.cc clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument] In file included from mini_racer_extension.cc:2: In file included from /Users/kobaltz/.rvm/rubies/ruby-2.4.4/include/ruby-2.4.0/ruby.h:33: In file included from /Users/kobaltz/.rvm/rubies/ruby-2.4.4/include/ruby-2.4.0/ruby/ruby.h:2012: /Users/kobaltz/.rvm/rubies/ruby-2.4.4/include/ruby-2.4.0/ruby/intern.h:47:19: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register] void rb_mem_clear(register VALUE*, register long); ^~~~~~~~~ /Users/kobaltz/.rvm/rubies/ruby-2.4.4/include/ruby-2.4.0/ruby/intern.h:47:36: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register] void rb_mem_clear(register VALUE*, register long); ^~~~~~~~~ 2 warnings generated. linking shared-object mini_racer_extension.bundle clang: warning: libstdc++ is deprecated; move to libc++ [-Wdeprecated] ld: library not found for -lstdc++ clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [mini_racer_extension.bundle] Error 1 make failed, exit code 2 Gem files will remain installed in /Users/kobaltz/.rvm/gems/ruby-2.4.4/gems/mini_racer-0.1.14 for inspection. Results logged to /Users/kobaltz/.rvm/gems/ruby-2.4.4/extensions/x86_64-darwin-17/2.4.0/mini_racer-0.1.14/gem_make.out An error occurred while installing mini_racer (0.1.14), and Bundler cannot continue. Make sure that `gem install mini_racer -v '0.1.14'` succeeds before bundling.

So the error ld: library not found for -lstdc++ is where the actual error lies.

To fix this, open the folder

open /Library/Developer/CommandLineTools/Packages/

Run the package macOS_SDK_headers_for_macOS_10.14.pkg

Then gem install mini_racer works!

This issue may not be only related to mini_racer as it could affect any gem that compiles an extension.