waiyan.yoon

Installing libv8 on MacOS Ventura

This error happened in MacOS Ventura 13.5.

The command with error:

» gem install libv8 -v '3.16.14.19'                                                                          1 ↵
Building native extensions. This could take a while...
ERROR:  Error installing libv8:
        ERROR: Failed to build gem native extension.

    current directory: /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/ext/libv8
/Users/user/.asdf/installs/ruby/2.5.8/bin/ruby -r ./siteconf20231122-54101-1ainoj5.rb extconf.rb
creating Makefile
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/disable-building-tests.patch
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/disable-werror-on-osx.patch
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/disable-xcode-debugging.patch
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/do-not-imply-vfp3-and-armv7.patch
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/do-not-use-MAP_NORESERVE-on-freebsd.patch
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/do-not-use-vfp2.patch
Applying /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/patches/fPIC-for-static.patch
Compiling v8 for x64
Using python 2.7.18
Using compiler: c++ (clang version 14.0.3)
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
Building v8 with env CXX=c++ LINK=c++  /usr/bin/make x64.release ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
        build/gyp/gyp --generator-output="out" build/all.gyp \
                      -Ibuild/standalone.gypi --depth=. \
                      -Dv8_target_arch=x64 \
                      -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
  CXX(target) /Users/user/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
clang: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../src/allocation.cc:33:
../src/utils.h:33:10: fatal error: 'climits' file not found
#include <climits>
         ^~~~~~~~~
1 error generated.

Solution

The best solution is to investigate whether therubyracer and libv8 can be removed in the first place. These libraries are based on v8 engine which is possibly replaced by modern JS build tools, or it's not even needed in the first place.

Alternative

# Install libv8 with system v8
gem install libv8 -v '3.16.14.19' -- --with-system-v8

# Find out the directory of your installed v8 binary, in this case, through homebrew:
$ gem install therubyracer -v 0.12.3 -- --with-v8-dir=/opt/homebrew/Cellar/v8/11.7.439.16

Source: https://github.com/rubyjs/libv8/issues/282

#rubygems-installation-errors