Thursday, April 7, 2022

[SOLVED] sassc bundler error: Gem::Ext::BuildError: ERROR: Failed to build gem native extension

Issue

Systems:

  • OS: Mac High Sierra (10.13.6)
  • Ruby: 2.5.3
  • Rails: 5.1.6
  • Bundler: 1.16.4

Running bundle install for a Rails app that includes a dependency on sassc 2.0.0 with native extensions gets a compile error.

Installing sassc 2.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: ~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0/ext
~/.rvm/rubies/ruby-2.5.3/bin/ruby -rrubygems ~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/rake-12.3.2/exe/rake
RUBYARCHDIR=~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/extensions/x86_64-darwin-17/2.5.0/sassc-2.0.0
RUBYLIBDIR=~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/extensions/x86_64-darwin-17/2.5.0/sassc-2.0.0
cd libsass
make lib/libsass.so
mkdir lib
/usr/bin/clang -Wall -O2 -I ~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0/ext/libsass/include -stdlib=libc++ -fPIC -fPIC -c -o src/cencode.o src/cencode.c
src/cencode.c:50:5: warning: declaration does not declare anything [-Wmissing-declarations]
                                __attribute__ ((fallthrough));
                                ^
src/cencode.c:64:5: warning: declaration does not declare anything [-Wmissing-declarations]
                                __attribute__ ((fallthrough));
                                ^
2 warnings generated.
c++ -Wall -O2 -std=c++0x -I ~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0/ext/libsass/include -stdlib=libc++ -fPIC -fPIC -c -o src/ast.o src/ast.cpp
c++: warning: couldn't understand kern.osversion '17.7.0
c++: error: unrecognized command line option '-stdlib=libc++'
make: *** [src/ast.o] Error 1
rake aborted!
Command failed with status (2): [make lib/libsass.so...]
~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0/lib/tasks/libsass.rb:31:in `block (2 levels) in <top (required)>'
~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0/lib/tasks/libsass.rb:13:in `block (3 levels) in <top (required)>'
~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0/lib/tasks/libsass.rb:12:in `block (2 levels) in <top (required)>'
~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/rake-12.3.2/exe/rake:27:in `<main>'
Tasks: TOP => lib/libsass.so
(See full trace by running task with --trace)

rake failed, exit code 1

Gem files will remain installed in ~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/gems/sassc-2.0.0 for inspection.
Results logged to ~/.rvm/gems/ruby-2.5.3@hyrax-app-on-wings-2019-02-01-SDC/extensions/x86_64-darwin-17/2.5.0/sassc-2.0.0/gem_make.out

An error occurred while installing sassc (2.0.0), and Bundler cannot continue.
Make sure that `gem install sassc -v '2.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

Research on How to Resolve

Tried - based on recommendations in github sassc

Ultimately, this recommended compiling separate from bundler and resolve any compile errors before trying bundler again. Following the instructions in the last ref (build-on-darwin), I was able to build directly, but still getting the same compiler error using bundler.

Refs:


Solution

Required an update to gcc. I tried to update using Homebrew and got permission errors in /usr/local.

Solution:

$ sudo chown -R $(whoami) $(brew --prefix)/*
$ brew upgrade gcc
$ bundle install

Reference: https://github.com/Homebrew/brew/issues/3228



Answered By - E L Rayle
Answer Checked By - Robin (WPSolving Admin)