ruby 错误:安装sass时出错:错误:无法构建gem本机扩展

inb24sb2  于 2023-01-25  发布在  Ruby
关注(0)|答案(2)|浏览(143)

我试图安装sass。我确实设法通过npm(1.14.1编译dart2js 2.0.0)安装了它,但是我需要用Ruby(Ruby Sass 3.5.6.)安装它。现在,这是我运行"sudo gem install sass"时的错误。

Building native extensions. This could take a while...
ERROR:  Error installing sass:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.25/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20181004-3909-1iytz3s.rb extconf.rb
checking for ffi.h... *** 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
--without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config 

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:456:in 'try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:571:in `block in try_compile'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:524:in `with_werror'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:571:in `try_compile'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:1091:in `block in have_header'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:942:in `block in checking_for'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:320:in `open'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:350:in `block in postpone'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:320:in `open'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:346:in `postpone'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:941:in `checking_for'
from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/
2.3.0/mkmf.rb:1090:in `have_header'
from extconf.rb:16:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

 /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.9.25/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.25 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.9.25/gem_make.out

我试过更新Ruby,删除通过npm安装的sass,按照一些建议更新xcode dev-tools。但是没有任何效果。我不知道是什么原因,因为我在从0更新到新的Mac OS Mojave之前有sass。
下面是mkmf.log文件:

package configuration for libffi is not found
"xcrun clang -o conftest - 
I/System/Library/Frameworks/Ruby.framework
/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 - 
I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/
include/ruby-2.3.0/ruby/backward - 
I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/
ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE - 
D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe - 
DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. - 
L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L.     
-lruby.2.3.0  -lpthread -ldl -lobjc "
In file included from conftest.c:1:
In file included from 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/
ruby-2.3.0/ruby.h:33:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/
ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
     ^~~~~~~~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

有什么想法吗?

n8ghc7c1

n8ghc7c11#

好的,解决方案已经找到了。如果出现此错误,请执行以下操作:
1.安装服务器虚拟机(https://rvm.io/
1.然后我必须运行以下命令才能使rvm工作:
如果sudo grep-q安全路径/etc/sudoers;然后sudo sh-c "回显导出rvmsudo安全路径= 1〉〉/etc/配置文件. d/rvmsecure路径. sh"&&回显已安装的环境变量;菲
1.接下来用rvm我删除了ruby:
rvm删除Ruby
1.最后安装ruby:
rvm安装ruby
1.不确定是否需要此步骤,但这是我控制台中的内容:Ruby是在没有文档的情况下构建的,要构建它,请运行:rvm文档生成-ri
所以我也运行了这个命令。在那之后我终于能够用sudo gem安装sass了。
现在起作用了!

5ktev3wc

5ktev3wc2#

在Mac中执行以下步骤安装SASS无错误
1.安装gpg brew安装-v gpg
1.安装定位键定位键2-接收键409 B6 B1796 C275462 A1703113804 BB82 D39 DC 0 E3 7D2 BAF 1CF 37 B13 E2069 D 6956105 BD 0 E739499 BDB
1.允许curl运行而不检查SSL(否则命令#4将抛出一个错误)echo unsecure〉〉~/.curlrc
1.安装rvm \curl -sSL -k https://get.rvm.io|猛击
1.要使用rvm,您将在运行#3中的命令后得到一个输出,如:要开始使用RVM,您需要运行source /Users/ymehta/.rvm/scripts/rvm Copy paste命令并按Enter键
1.删除现有ruby版本rvm删除ruby
1.安装ruby rvm安装ruby

  1. rvm文档生成-ri
    1.安装sass sudo gems安装sass
    1.检查sass版本sass --版本
    https://gist.github.com/Yashvi-Mehta/9ad81330d1703f12a00b63cf20c9cdb3中可以找到相同的步骤

相关问题