【问题标题】:Failed to build gem native extension on Windows无法在 Windows 上构建 gem 原生扩展
【发布时间】:2015-06-23 14:41:23
【问题描述】:

我正在尝试在我的 Windows 机器上安装 dandelion gem,但一直失败:

C:\Users\William>gem install dandelion --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing dandelion:
ERROR: Failed to build gem native extension.

C:/Ruby22/bin/ruby.exe -r ./siteconf20150623-7568-1ikffjg.rb extconf.rb
checking for gmake... no
checking for make... yes
checking for cmake... yes
checking for pkg-config... yes
-- cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_
FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -G "Unix Makefiles"
-- C:\DevKit\bin/make.exe
checking for main() in -lgit2... *** 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:/Ruby22/bin/$(RUBY_BASE_NAME)
--use-system-libraries
--with-git2-dir
--without-git2-dir
--with-git2-include
--without-git2-include=${git2-dir}/include
--with-git2-lib
--without-git2-lib=${git2-dir}/lib
--with-git2lib
--without-git2lib
C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:541:in `try_link0'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:735:in `try_func'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:966:in `block in have_library'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
from C:/Ruby22/lib/ruby/2.2.0/mkmf.rb:961:in `have_library'
from extconf.rb:89:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22/lib/ruby/gems/2.2.0/gems/rugged-0.2
2.1b1 for inspection.
Results logged to C:/Ruby22/lib/ruby/gems/2.2.0/extensions/x86-mingw32/2.2.0/rug
ged-0.22.1b1/gem_make.out

声明“您必须先安装开发工具”的错误令人头疼。我已经安装了 DevKit。

任何想法如何解决这个错误?

【问题讨论】:

  • 它还写着Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.。阅读日志文件(或至少发布它们,以便我们为您提供帮助)以获取更多信息。但看起来你缺少 libgit2。 You have to install development tools first. 有点混乱,但与 RubyInstaller DevKit 无关。
  • 感谢您的回复。这是日志:pastebin.com/17m528Yn
  • 我还应该注意到 OpenSSL 错误很奇怪。我在 PATH 上有那个设置。不知道那里发生了什么。
  • @WilliamC 请避免将关键元素(如日志)排除在外部服务中。
  • @Michal Szyndel 但我确实包含了我的日志...

标签: ruby windows gem cmake devkit


【解决方案1】:

这是一个有趣的。我会大胆猜测一下,你有一个位于 C:/Program Files (x86)/libgit2/lib 中的 libgit2 版本,并且该文件夹不知何故在你的 Path 或其他一些环境变量中。

解决方法是将该文件夹从它可能所在的环境变量中取出。这应该让rugged 正确构建。

问题

gcc 尝试测试libgit2 库时,它发现它可能在C:/Program Files (x86)/libgit2/lib 中并使用-LC:/Program Files (x86)/libgit2/lib

问题是它没有正确转义,导致

gcc: error: Files: No such file or directory
gcc: error: (x86)/libgit2/lib: No such file or directory

这其实也是Ruby不能安装在有空格的文件夹中的原因。

附带说明:我想指出的是,除了常规的 DevKit 之外,您还安装了 cmakepkg-config 某处并在您的 Path

【讨论】:

  • 感谢您的回复。你是对的,我的程序文件(x86)目录中有一个 libgit2 的副本,它在我的 PATH 上。我会删除它。
  • 另外,关于您上一条评论的问题。最初,我刚安装 DevKit 时遇到错误,所以我添加了 cmake 和 pkg-config。这清除了错误。我应该从我的 PATH 中删除它们吗?
  • 不,这些是必要的,我只是为可能偶然发现此问题的其他人添加了这一点。
  • 我从路径中删除了 libgit2,但它仍然出错。这是错误消息:pastebin.com/KiCwAjNa 这是日志:pastebin.com/dHuLZGDX
  • 还在那儿找,看第 385 行
猜你喜欢
  • 2014-10-25
  • 2014-12-04
  • 1970-01-01
  • 1970-01-01
  • 2015-07-20
  • 2015-06-18
  • 2016-03-08
  • 2012-07-26
相关资源
最近更新 更多