ruby Gem安装报错:你得先安装开发工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27768420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:39:47  来源:igfitidea点击:

Gem installation error: You have to install development tools first

rubywindowssinatra

提问by Generic_User_ID

I tried installing the gem 'sinatra-websocket', but when I ran gem install sinatra-websocket, I got this error...

我尝试安装 gem ' sinatra-websocket',但是当我运行时gem install sinatra-websocket,出现此错误...

ERROR: Failed to build gem native extension

ERROR: Failed to build gem native extension

... along with ...

... 随着 ...

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>'

Here's what the mkmffile in C:\Ruby193\lib\ruby\gems\1.9.1\gems\thin-1.6.3\ext\thin_parserlooks like:

这是mkmf文件中的C:\Ruby193\lib\ruby\gems\1.9.1\gems\thin-1.6.3\ext\thin_parser样子:

"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 */

I'm using Windows 7.

我正在使用 Windows 7。

Why am I getting the error? There's a line stating "could not create Makefile...", but is that relevant?

为什么我收到错误?有一行说明“无法创建 Makefile...”,但这是否相关?

回答by Alex Chin

Have you run:

你有没有跑过:

xcode-select --install

To install the Xcode Developer tools?

要安装 Xcode Developer 工具?

回答by Cereal

edit: rubyinstaller now provides installs with the devkit included. These are labelled on the download page.

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

Sounds like you're missing the devtools for ruby.

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

You can get them here: http://rubyinstaller.org/downloads/just scroll down to "Development Kit".

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

Download and extract that to anywhere you want. Open up the folder in command prompt and run ruby dk.rb init. This will create a config file detailing your ruby installations. Check this config file before continuing to confirm the paths to your ruby installation are correct.

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

Now run ruby dk.rb install. This will install the development kit.

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

Restart command prompt, and try to install the gem again.

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

回答by Divyanshu Rawat

I was having this issue on MacOS Mojave(10.14.1). Installing latest ruby via Homebrew and setting some env variables solved it for me:

我在 MacOS Mojave(10.14.1) 上遇到了这个问题。通过 Homebrew 安装最新的 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"

回答by tw airball

If you're on Mac OS 10.14 (Mojave) try

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

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

Credit to Roy Huang Reference: https://stackoverflow.com/a/55732339/1598551

归功于 Roy Huang 参考:https: //stackoverflow.com/a/55732339/1598551

回答by Gowtham Gopalakrishnan

If you're on Mac and recently upgraded your Xcode tools, run the following commands:

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

sudo xcode-select --install
sudo xcodebuild -license

回答by maheshsgr

This worked for me:

这对我有用:

sudo xcode-select -switch /

sudo xcode-select -switch /

回答by Behlül U?ar

This means you don't have compiler tools installed. For mac xcode-select --installinstalls them. For linux or other systems you can use package managers, for example apt install cmakeshould install the necessary build tools for systems having apt package manager.

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