【问题标题】:Gem installation error: You have to install development tools first (Windows)Gem安装报错:必须先安装开发工具
【发布时间】:2021-12-17 05:45:54
【问题描述】:

我尝试安装 gem 'sinatra-websocket',但是当我运行 gem install sinatra-websocket 时,我收到了这个错误...

ERROR: Failed to build gem native extension

...连同...

C:/Ruby193/bin/ruby.exe extconf.rb
checking for main() in -lc... *** 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=C:/Ruby193/bin/ruby
    --with-thin_parser-dir
    --without-thin_parser-dir
    --with-thin_parser-include
    --without-thin_parser-include=${thin_parser-dir}/include
    --with-thin_parser-lib
    --without-thin_parser-lib=${thin_parser-dir}/lib
    --with-clib
    --without-clib
C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:845:in `block in have_library'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:840:in `have_library'
    from extconf.rb:4:in `<main>'

C:\Ruby193\lib\ruby\gems\1.9.1\gems\thin-1.6.3\ext\thin_parser 中的 mkmf 文件如下所示:

"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -DFD_SETSIZE=2048  -DFD_SETSIZE=2048  -O3 -fno-omit-frame-pointer -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/Ruby193/lib -L.   -march=i486   -lmsvcrt-ruby191  -lshell32 -lws2_32 -limagehlp -lshlwapi  "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

我使用的是 Windows 7。

为什么我会收到错误消息?有一行说“无法创建 Makefile...”,但这有关系吗?

【问题讨论】:

  • mkmf.log文件可以在gem的安装目录下找到。
  • @siaw23 我已经添加了文件的内容
  • 你安装了 C 编译器吗?
  • 我以前用过的是Mingw。从this 你可以尝试make -vgcc -v 来检查。您可以尝试安装the Ruby dev kit
  • 看看这个答案,它比我能给出的任何建议都详细而且更好。 stackoverflow.com/a/11484346/335847

标签: ruby windows sinatra


【解决方案1】:

你跑了吗:

xcode-select --install

要安装 Xcode 开发者工具?

【讨论】:

  • 我认为错误中引用的“开发工具”与 xcode 没有任何关系,尤其是考虑到这是在 Windows 上。
  • 最初的问题肯定是说 Windows,但无论如何 - 这在 Mac 上帮助了我!
  • 正是我在 OSX El Capitan 上所缺少的。
  • 'xcode-select' 不是内部或外部命令、可运行程序或批处理文件。
  • (在 Mac OSx Mojave 上)运行 xcode-select --install 后,关闭并重新打开终端。然后,运行sudo xcodebuild -license,按照说明操作,最后接受许可协议。在我的实验中,这是解决问题的方法。
【解决方案2】:

编辑:rubyinstaller 现在提供包含 devkit 的安装。这些标记在下载页面上。

听起来您缺少 ruby​​ 的开发工具。

您可以在此处获取它们:http://rubyinstaller.org/downloads/ 只需向下滚动到“开发工具包”。

下载并将其提取到您想要的任何地方。在命令提示符下打开文件夹并运行ruby dk.rb init。这将创建一个配置文件,详细说明您的 ruby​​ 安装。在继续确认您的 ruby​​ 安装路径正确之前,请检查此配置文件。

现在运行ruby dk.rb install。这将安装开发工具包。

重新启动命令提示符,并尝试再次安装 gem。

【讨论】:

    【解决方案3】:

    我在 MacOS Mojave(10.14.1) 上遇到了这个问题。通过 Homebrew 安装最新的 ruby​​ 并设置一些环境变量为我解决了这个问题:

    (复制自brew info ruby指令)

    export PATH="/usr/local/opt/ruby/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/ruby/lib"
    export CPPFLAGS="-I/usr/local/opt/ruby/include"
    export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
    

    【讨论】:

    • 如果您通过 brew 安装了 ruby​​,您可以使用 brew info ruby 获取这些环境变量
    • 这个答案解决了我在最近的 OSX 更新后尝试使用 Sass 编译器时遇到的问题
    • 这行得通,节省了我的时间,感谢 loooooot!
    • 也为我工作!感谢您的精彩回答!
    • 这适用于失败的inspec 安装
    【解决方案4】:

    如果您使用的是 Mac OS 10.14 (Mojave),请尝试

    cd  /Library/Developer/CommandLineTools/Packages/;
    open macOS_SDK_headers_for_macOS_10.14.pkg
    

    感谢 Roy Huang 参考:https://stackoverflow.com/a/55732339/1598551

    【讨论】:

    • 我能够在 Mojave 上正确执行您的步骤,但他们没有帮助我解决“您必须先安装开发工具”错误。
    【解决方案5】:

    这意味着您没有安装编译器工具。对于 mac xcode-select --install 安装它们。对于 linux 或其他系统,您可以使用包管理器,例如 apt install cmake 应该为具有 apt 包管理器的系统安装必要的构建工具。

    【讨论】:

      【解决方案6】:

      这对我有用:

      sudo xcode-select -switch /

      【讨论】:

      • 我已经安装了命令行工具,这也对我有用。谢谢!
      • 没有帮助我
      • 帮我解决了失败gem install psych -v '3.0.2' --source 'https://rubygems.org/'
      • xcode-select: error: invalid developer directory '/' 我收到了这个错误
      • 这个答案需要更多解释。它 A) 需要 sudo,B) 我不知道 xcode 是什么,C) 看起来要在根文件夹上操作,这对新手来说是三个巨大的危险信号。
      【解决方案7】:

      如果您使用的是 Mac 并且最近升级了 Xcode 工具,请运行以下命令:

      sudo xcode-select --install
      sudo xcodebuild -license
      

      【讨论】:

      • 我能够在 Mojave 上正确执行您的步骤,但他们没有帮助我解决“您必须先安装开发工具”错误。
      【解决方案8】:

      我在 Ubuntu 18.04 上遇到了同样的问题。 Ubuntu 上的修复是安装 ubuntu-dev-tools 包:

      $ sudo apt-get install ubuntu-dev-tools
      

      【讨论】:

      • 谢谢你,为我工作!在 Ubuntu 20.04
      • 谢谢。我也在 20.04 上为此苦苦挣扎了一段时间
      【解决方案9】:

      如果您安装了多个版本的 Xcode,请确保选择最新版本的命令行工具,否则 gem 将无法找到它们。

      【讨论】:

        【解决方案10】:

        这是我的 mac OSX 解决方案:

        在终端应用程序中:

        第 1 步:确保您已通过以下脚本安装了 Xcode 开发者工具:

        xcode-select --install

        第 2 步:通过脚本升级您的 ruby​​:

        brew install ruby

        第 3 步:重试。

        【讨论】:

        • 我在 Earch 上尝试了任何东西,超过两天,我在 MacOS 10.15.7 catalina,xcode 12.3 中,尝试开发 nativescript 应用程序,最后这个解决方案对我有用,并且成功安装了 cocoapods。谢谢老兄。
        【解决方案11】:

        我的问题是我更新到 macOS Big Sur,不知何故,命令行工具已经过时了。

        我知道这一点是因为,当我尝试运行 brew install rbenv 时,我收到了这个错误:

        Error: Your Command Line Tools (CLT) does not support macOS 11.
        It is either outdated or was modified.
        Please update your Command Line Tools (CLT) or delete it if no updates are available.
        Update them from Software Update in System Preferences or run:
          softwareupdate --all --install --force
        
        If that doesn't show you any updates, run:
          sudo rm -rf /Library/Developer/CommandLineTools
          sudo xcode-select --install
        
        Alternatively, manually download them from:
          https://developer.apple.com/download/more/.
        

        所以我跑了

        sudo rm -rf /Library/Developer/CommandLineTools
        sudo xcode-select --install
        

        完成后,gem安装成功。

        【讨论】:

        • 这在没有删除 CommandLineTools 目录的情况下工作得很好?谢谢!
        • 感谢您帮助我在 m1 Mac mini 上安装可可豆荚。
        【解决方案12】:

        我最近升级到 MAC OS big sur,运行 gem install 时开始报错...

        解决方案是完全删除 CLT 并再次运行安装。

        可选:

        酿造升级

        运行:

        sudo rm -rf /Library/Developer/CommandLineTools

        sudo xcode-select --install

        【讨论】:

          【解决方案13】:

          尝试了所有以前的答案,但没有一个有效。

          改为这样做:

          brew install cocoapods
          

          【讨论】:

          • 也为我工作。我与The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. 斗争了一段时间。
          • 我是 Mac 用户并且正在运行 Xcode。这对我有用。
          【解决方案14】:

          ma​​cOS Catalina 上;在运行 $ brew install coreutils (credit) 之后——我跟随了 Evan Hoffman 的旧版 article,安装了 chef(嵌入了最新的稳定版 Ruby

          $ curl -L https://www.getchef.com/chef/install.sh | sudo bash

          然后我可以安装所需的任何 gem,现在已安装所有必需的开发工具;

          $ sudo gem install -V &lt;gem&gt;

          您在 Big Sur 的里程可能会有所不同

          【讨论】:

            【解决方案15】:

            实际上,真正的问题是当一个人从 macOS 的主要版本升级到另一个并安装更新的 Xcode 时。

            cd /Library/Developer/CommandLineTools
            ls -l SDKs/
            total 0
            lrwxr-xr-x  1 root  wheel   14 Feb  4 21:41 MacOSX.sdk -> MacOSX11.1.sdk
            drwxr-xr-x  8 root  wheel  256 Feb  4 21:43 MacOSX10.15.sdk
            drwxr-xr-x  7 root  wheel  224 Feb  4 21:43 MacOSX11.1.sdk
            

            访问 Apple 的开发者网站并手动下载 CLI 工具后,该文件夹包含以下内容:

            $> ls -l SDKs/
            lrwxr-xr-x  1 root  wheel   14 May  4 18:10 MacOSX.sdk -> MacOSX11.3.sdk
            drwxr-xr-x  8 root  wheel  256 May  4 18:10 MacOSX10.15.sdk
            drwxr-xr-x  7 root  wheel  224 Feb  4 21:43 MacOSX11.1.sdk
            drwxr-xr-x  7 root  wheel  224 Mar 16 10:03 MacOSX11.3.sdk
            lrwxr-xr-x  1 root  wheel   14 May  4 18:09 MacOSX11.sdk -> MacOSX11.3.sdk
            

            您可能仍需要使用以下命令重置 Xcode:

            $> sudo xcode-select --reset
            $> sudo xcodebuild -license
            

            验证:

            $> sudo xcode-select --print-path
            /Applications/Xcode.app/Contents/Developer
            

            最后,如果你仍然看到编译错误,你需要密切注意编译器错误是什么并解决它。例如,在我的例子中,只是在 macOS Big Sur 中,clang 需要特殊的参数来添加声明(结构)。它被修复了:

            export CFLAGS="-fdeclspec $CFLAGS"
            

            如果您好奇(或任何在线寻找 Ruby 3.0.x 答案的人),这就是错误:

            /usr/local/Cellar/ruby/3.0.1/include/ruby-3.0.0/ruby/internal/fl_type.h:285:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
            

            【讨论】:

              【解决方案16】:

              试试rvm install ruby --latest

              如果已经安装,试试rvm reinstall ruby --latest

              $ sudo gem install -V &lt;gem&gt;

              为我工作。

              【讨论】:

                【解决方案17】:

                对于 Ubuntu 20.04.3 LTS (Focal Fossa) -- WSL

                之前有一些依赖需要解决,试试下面的命令序列:

                # if ERROR: 'Gem installation error: You have to install development tools first'
                # BEFORE installing the dev-tools, install dependencies:
                # if ERROR: 'GCC fatal error: stdio.h: No such file or directory'
                $ sudo apt-get install libc6
                # https://stackoverflow.com/a/20150282/5078874
                $ sudo apt-get install libc6-dev
                $ sudo apt-get install libffi-dev
                
                # Now, go for the development tools
                # https://stackoverflow.com/a/63442072/5078874
                $ sudo apt-get install ubuntu-dev-tools
                
                # Finally, try again
                $ bundle update --bundler
                # ... enjoy :)
                

                参考资料:

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2021-01-12
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-05-11
                  相关资源
                  最近更新 更多