简体   繁体   English

无法在Windows上构建gem本机扩展

[英]Failed to build gem native extension on Windows

I'm attempting to install the dandelion gem on on my Windows machine, but it keeps failing: 我正在尝试在Windows计算机上安装蒲公英 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

The error that states "you have to install development tools first" is a head-scratcher. 指出“您必须首先安装开发工具”的错误令人头疼。 I have already installed DevKit. 我已经安装了DevKit。

Any ideas how to solve this error? 任何想法如何解决此错误?

This is a fun one. 这很有趣。 I'm going to take a wild guess and say that you have a version of libgit2 located in C:/Program Files (x86)/libgit2/lib and that folder is somehow in your Path or possible some other environment variable. 我要libgit2猜测,并说您在C:/Program Files (x86)/libgit2/lib有一个libgit2版本,并且该文件夹在您的Path或某个其他环境变量中。

The fix is to take that folder out of what environment variable that it could be in. That should let rugged build correctly. 解决方法是将该文件夹移出它可能位于的环境变量中。这样可以使rugged正确构建。

The Problem 问题

When gcc is trying to test for the libgit2 library it sees it could possibly be in C:/Program Files (x86)/libgit2/lib and uses -LC:/Program Files (x86)/libgit2/lib . gcc尝试测试libgit2库时,它发现它可能位于C:/Program Files (x86)/libgit2/lib并使用-LC:/Program Files (x86)/libgit2/lib

The problem is that it isn't properly escaped, which leads to 问题是它没有被正确地转义,这导致

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

This is actually the same reason why Ruby can't be installed in folders with spaces. 这实际上就是为什么无法将Ruby安装在带空格的文件夹中的原因。

As a side note: I'd like to point out that in addition to the regular DevKit you also have cmake and pkg-config somewhere installed and in your Path 附带说明: 我想指出,除了常规的DevKit之外,您还可以在Path某些位置安装cmakepkg-config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM