【问题标题】:Installing ncurses for ruby on Windows在 Windows 上为 ruby​​ 安装 ncurses
【发布时间】:2012-10-17 12:39:58
【问题描述】:

我正在尝试在 Windows 上为 ruby​​ 安装 ncurses。我之前没有在我的机器上安装 ncurses。我认为拥有"ruby devkit",它所要求的就足够了,但现在我被要求指定选项......我不知道要选择哪些选项,或者我是否需要做/安装其他东西要安装的 gem:

C:\Ruby193\Devkit>gem install ncurses -- --ruby=C:/Ruby193/bin/ruby --without-make-prog --without-opt-dir
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing ncurses:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb --ruby=C:/Ruby193/bin/ruby --without-make-prog --without-opt-dir
C:/Ruby193/lib/ruby/1.9.1/shellwords.rb:35:in `shellsplit': undefined method `scan' for false:FalseClass (NoMethodError)
        from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:2216:in `<top (required)>'
        from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from extconf.rb:22:in `<main>'


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/ncurses-0.9.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/ncurses-0.9.1/./gem_make.out

多么痛苦,我只想安装这个 gem,这样我就可以运行它了:

require 'curses'
cols = Curses.stdscr.maxx
msg = "random_string"
str = msg.center(msg.length + cols - msg.length - 5 - 3)
puts "<!-- #{str}-->"

【问题讨论】:

    标签: ruby windows ncurses


    【解决方案1】:

    更新版本:

    1. 获取 ncurses(MinGW 端口):http://invisible-island.net/ncurses/
    2. 把它放在 C:\ncurses
    3. gem install curses --platform=ruby -- --with-ncurses-dir="C:\ncurses"
    4. 将 C:\ncurses\bin 的内容复制到路径中的某个位置

    C:\ncurses 可以是任意目录

    【讨论】:

      【解决方案2】:

      我已经设法为 ruby​​ 2.2 做到了,默认情况下它没有附带诅咒,但我花了一段时间:

      • 从SourceForge下载PDCurses;
      • 解压;
      • 将其内容复制到 ruby​​ 可以看到的文件夹中。我不确定我使用的是哪一个,我想我将它复制到多个,直到它起作用。 ruby -e 'puts $:' 可能会有所帮助;
      • 安装诅咒,gem instal curses。如果上一步错误,这将失败;
      • 完成:D

      此方法不适用于其他 gem,例如 ffi-ncurses。 提示:大部分curses功能来自Window class,默认自带curses。

      【讨论】:

      • 请修正这个答案中的错别字。
      【解决方案3】:

      更新:SourceForge 似乎不再托管适用于 Windows 的 NCurses 二进制文件。这个答案现在实际上已经过时了。对不起! (截至 2015 年 8 月,GNU NCurses Page 列出了“新”v6.0 版本,比我的回答中的 0.9.1 版本更新。)

      我终于让它工作了(在我需要它多年后......)没有 Cygwin、PDCurses 或手动构建 NCurses 源。说明可用on my blog。供参考:

      • 从SourceForge 下载最新的 NCurses 二进制文件 (0.9.1)。
      • 将文件解压缩到您机器上的某个位置。
      • 通过运行ruby -e 'puts $:' 找出 Ruby 搜索库的位置
      • 将 ncurses.so 和 lib\ncurses.rb 从 NCurses 目录复制并粘贴到您选择的目录中。将它们都放在根目录中。
      • 运行支持 NCurses 的应用。

      它有效。没有 PDCurses!

      【讨论】:

      • 死链接:指向您博客的链接已死
      • @Nisanio 这个答案应该有足够的信息。我的博客确实早就死了。
      • SourceForge 的死链接。 RIP 回答
      • @SlySherZ 我相信你可以通过谷歌搜索并在某处找到 NCurses 0.9.1 二进制文件。仅供参考,GNU 宣布 NCurses 6.0。见this link。
      • @ashes999 谢谢!我已经找到了,但是我花了比我希望的更多的时间:D
      【解决方案4】:

      安装gem时需要curses lib;所以首先你需要安装 NCurses 用你的 msys2

      https://sourceforge.net/p/mingw-w64/wiki2/NCurses/

      下载 NCurses(撰写本文时为 v5.9):http://ftp.gnu.org/pub/gnu/ncurses/ 在源目录中

      然后解压并在 MSYS shell 中:

      ./configure --host=x86_64-w64-mingw32 --enable-term-driver --enable-sp-funcs --prefix=/some/prefix

      制作

      检查

      进行安装

      然后如链接中所述: https://github.com/ruby/curses/issues/13

      在 gem install 中使用 --platform=ruby ,--with-curses-include ,--with-curses-lib 标志

      【讨论】:

        【解决方案5】:

        截至 2020 年 2 月(可能更早),您可以使用以下命令安装 ncurses 库

        gem install curses
        

        至少在 Ruby 2.6.5 上可以正常工作

        【讨论】:

          【解决方案6】:

          ruby ncurses gem 需要在机器上安装 ncurses。据我所知,ncurses 尚未移植到 Windows。所以我认为你不会让它发挥作用。

          可能还有其他方法可以确定 Windows 上的屏幕宽度,但我无法帮助您。

          【讨论】:

          • require "io/console"; rows, cols = STDIN.winsize
          【解决方案7】:

          我已经从 sourceforge 成功下载了ncurses 0.9.1 binaries,所以该库仍然可用。

          然后我尝试使用原生 Ruby 和 IronRuby 1.1.3

          1. 将两个文件(ncurses.so ncurses.rb)放入

            C:\Ruby\Ruby193\lib\ruby\1.9.1

            使用原生 Ruby 时出错

            找不到指定的模块。 - C:/Ruby/Ruby193/lib/ruby/1.9.1/ncurses.so (LoadError)

          2. 将它们放在这里(对于 IronRuby) C:\Program Files (x86)\IronRuby 1.1\Lib\ruby\1.9.1

            给予

            该模块应包含程序集清单。 (HRESULT 异常:0x80131018)

          【讨论】:

          • zip 文件中的库不是 ncurses,而是 pdcurses,有人已将其重命名以简化(他们的)工作。自 2011 年以来,mingw 有一个 ncurses 端口,但 ruby​​ 的打包程序还没有抓住这一点。
          • 这不是答案。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-06
          • 1970-01-01
          • 1970-01-01
          • 2014-03-23
          • 1970-01-01
          相关资源
          最近更新 更多