代码之家  ›  专栏  ›  技术社区  ›  Dolphin

编译器未能生成可执行文件。在macOS中安装unf_ext时发生运行时错误

  •  0
  • Dolphin  · 技术社区  · 4 年前

    当我在macOS 10.15.7中使用此命令进行安装时 unf_ext :

    sudo gem install unf_ext -v '0.0.7.7' --source 'https://gems.ruby-china.com'
    

    显示此错误:

    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /Users/dolphin in PATH, mode 040777
    Building native extensions. This could take a while...
    ERROR:  Error installing unf_ext:
        ERROR: Failed to build gem native extension.
    
        current directory: /Library/Ruby/Gems/2.6.0/gems/unf_ext-0.0.7.7/ext/unf_ext
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20210121-81858-8bev42.rb extconf.rb
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /Users/dolphin in PATH, mode 040777
    checking for -lstdc++... *** 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.6/usr/bin/$(RUBY_BASE_NAME)
        --with-static-libstdc++
        --without-static-libstdc++
        --with-stdc++lib
        --without-stdc++lib
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467: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.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:789:in `try_func'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1016:in `block in have_library'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1011:in `have_library'
        from extconf.rb:6:in `<main>'
    
    To see why this extension failed to compile, please check the mkmf.log which can be found here:
    
      /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/unf_ext-0.0.7.7/mkmf.log
    
    extconf failed, exit code 1
    
    Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/unf_ext-0.0.7.7 for inspection.
    Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/unf_ext-0.0.7.7/gem_make.out
    

    我已经试过了:

    $ xcode-select --install
    
    xcode-select: error: command line tools are already installed, use "Software Update" to install updates
    

    仍然不起作用,我该怎么办才能修复它?

    0 回复  |  直到 4 年前
        1
  •  1
  •   Robin Chen    3 年前

    cat/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/unf.ext-0.7.7/gem_make.out可以得到详细的原因。

    在我看来,被抛弃的原因是: /库/开发人员/命令行工具/sdk/MacOSX.sdk/系统/库/框架/Ruby.framework/版本/2.6/usr/include/Ruby-2.6.0/Ruby/Ruby.h:24:10:注意:在框架'Ruby'中找不到头文件'config.h'(从'/Library/Developer/CommandLineTools/sdk/MacOSX.sdk/System/Library/Frameworks'加载) 生成1个错误。

    这似乎是Xcode和macOS版本不兼容的问题。macOS 10.15和Xcode 12不能很好地协同工作。你可以查一下 https://github.com/CocoaPods/CocoaPods/issues/10286

        2
  •  0
  •   sxc731 Paul Samsotha    2 年前

    只是澄清了Robin Chen的回答,我支持提供链接到 CocoaPods ticket .

    这似乎是Xcode/macOS版本不匹配的问题(我有Monterey 12.6.3和Xcode 14.2)。

    按照中提供的方法 this comment 解决了我的问题(全部归功于评论的作者);即:

    export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX$(sw_vers -productVersion | cut -f1 -d\.).sdk
    ls -l $SDKROOT                   # check we're pointing to the right place
    sudo gem install ...