oneclick / rubyinstaller2

MSYS2 based RubyInstaller for Windows
https://rubyinstaller.org
BSD 3-Clause "New" or "Revised" License
654 stars 249 forks source link

Unable to build native extension #268

Closed enumag closed 2 years ago

enumag commented 2 years ago

What problems are you experiencing?

$ gem install zlib
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR:  Error installing zlib:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/zlib-2.1.1/ext/zlib
C:/Ruby31-x64/bin/ruby.exe -I C:/Ruby31-x64/lib/ruby/3.1.0 -r ./siteconf20220412-19244-gwhw3p.rb extconf.rb
checking for deflateReset() in -lz... *** 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:/Ruby31-x64/bin/$(RUBY_BASE_NAME)
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --with-z-dir
        --without-z-dir
        --with-z-include
        --without-z-include=${z-dir}/include
        --with-z-lib
        --without-z-lib=${z-dir}/lib
        --with-zlib
        --without-zlib
C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:498:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:591:in `try_link0'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:609:in `try_link'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:830:in `try_func'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1065:in `block in have_library'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1007:in `block in checking_for'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:362:in `block (2 levels) in postpone'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:332:in `open'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:362:in `block in postpone'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:332:in `open'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:358:in `postpone'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1006:in `checking_for'
        from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1060:in `have_library'
        from extconf.rb:14:in `block in <main>'
        from extconf.rb:14:in `each'
        from extconf.rb:14:in `find'
        from extconf.rb:14:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/zlib-2.1.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/zlib-2.1.1 for inspection.
Results logged to C:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/zlib-2.1.1/gem_make.out

Steps to reproduce

The development kit should be installed I think. I went through the steps during installation. Not sure why the error above still says "You have to install development tools first."

Also I made sure to install Ruby into a directory without spaces since I read that it might cause issues.

What's the output from ridk version?

ridk: command not found

I double checked that C:\Ruby31-x64\bin is in PATH but there is no ridk or ridk.exe there. Only ridk.cmd and ridk.ps1. Not sure why.

If I open terminal in C:\Ruby31-x64\bin and run ./ridk.cmd version then I get this:

---
ruby:
  path: C:/Ruby31-x64
  version: 3.1.1
  platform: x64-mingw-ucrt
  cc: gcc.exe (Rev9, Built by MSYS2 project) 11.2.0
ruby_installer:
  package_version: 3.1.1-1
  git_commit: d9d39f1
msys2:
  path: C:\Ruby31-x64\msys64
sh: GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)
os: Microsoft Windows [Version 10.0.19043.1586]
ccmywish commented 2 years ago

Hi, @enumag

It seemed that you installed a gem right away after you installed Ruby with devkit. But in my latest experience on Ruby 3.1.1, you should reboot first to make the env path work.

The ridk command is surely a script like ridk.cmd and ridk.ps1, so I think you can try gem install zlib again when your ridk command not shows:

ridk: command not found

Hope it helps.

mohits commented 2 years ago

Hi @enumag - thanks for the detailed information. Can you try this:

I have edited the comment based on what I see with my setup.

I changed my path to the minimal:

$ path
PATH=C:\Ruby30-x64\bin;d:\tools;c:\Windows\System32

Then, I tried to install zlib and it worked fine for me.

$ gem install zlib
Fetching zlib-2.1.1.gem
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
Successfully installed zlib-2.1.1
Parsing documentation for zlib-2.1.1
Installing ri documentation for zlib-2.1.1
Done installing documentation for zlib after 1 seconds
1 gem installed

Just to confirm - I know you downloaded the version with the DevKit but did you install the DevKit? This all the more because of this note:

The development kit should be installed I think. I went through the steps during installation since you said:  "You have to 
install development tools first.

Could you take a look at the step-by-step instructions on this page: https://notepad.onghu.com/2021/ruby3-windows-day0-install-hello_world/ to see if you did all the steps? It's written for 3.0 but should be identical for Ruby 3.1 also.

I will install Ruby 3.1 on my side and try the same steps later today to see if I can replicate the issue that you are facing.

enumag commented 2 years ago

It started to work on it's own, even without reboot. The only thing I'm aware of doing differently is that I tried it from Window's command prompt instead of from git bash I got installed along with git for windows. Strange but I'm not complaining.

Olimiya commented 2 years ago

I met the same problem. And my solution is change the rubyinstaller-devkit from 3.1.1(newest) to 3.0.3. And I solve it.