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

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

系统:

运行 bundle install 对于 Rails 应用程序,该应用程序包含对具有本机扩展的 sassc 2.0.0 的依赖性会出现编译错误。

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.

研究如何解决

已尝试 - 基于 github sassc

中的建议

最终,这建议与捆绑器分开编译,并在再次尝试捆绑器之前解决所有编译错误。按照上一篇参考文献(build-on-darwin)中的说明,我能够直接构建,但仍然使用 bundler 遇到相同的编译器错误。

参考文献:

需要更新 gcc。我尝试使用 Homebrew 进行更新,但在 /usr/local.

中出现权限错误

解决方案:

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

参考:https://github.com/Homebrew/brew/issues/3228

这解决了它:

gem 安装 sassc --version=2.1.0 -- --disable-march-tune-native

在基于 Ruby 2.5.8 的 Docker CI 容器中的 Linux 上遇到了这个问题,并用这个解决了它:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt install gcc