【问题标题】:rbenv and gems that require C extensions需要 C 扩展的 rbenv 和 gems
【发布时间】:2013-10-10 07:47:46
【问题描述】:

所以我正在尝试安装audite gem,但遇到了 rbenv 问题:

$ bundle install
Fetching gem metadata from https://rubygems.org/...
Installing audite (0.3.0)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /opt/boxen/rbenv/versions/1.9.3-p448/bin/ruby extconf.rb
checking for mpg123.h... no
*** 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=/opt/boxen/rbenv/versions/1.9.3-p448/bin/ruby
please install mpg123 headers


Gem files will remain installed in /opt/boxen/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/audite-0.3.0     for inspection.
Results logged to /opt/boxen/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/audite-0.3.0/ext/mpg123/gem_make.    out

An error occurred while installing audite (0.3.0), and Bundler cannot continue.
Make sure that `gem install audite -v '0.3.0'` succeeds before bundling.

我知道这些 gem 需要 c 扩展,我用自制软件安装了它们。如果我进入地窖寻找自制软件,我可以看到它正在寻找的文件 (mpg123.h)

/opt/boxen/homebrew/Cellar/mpg123/1.15.4/include/mpg123.h

那么,有没有一种方法可以将它添加到 rbenv 环境中,而不仅仅是 sim-linking 或直接复制到 /opt/boxen/rbenv/versions/1.9.3-p448/

【问题讨论】:

    标签: ruby homebrew rbenv boxen


    【解决方案1】:

    将 homebrew include 目录添加到您的路径中,rubygems 会找到它。这不是 rbenv 真正的问题。

    在默认安装中,自制软件将软件包的所有 include 文件夹符号链接到 /usr/local/include,在您的情况下,这些文件夹应该在 /opt/boxen/homebrew/include 中。看看周围,应该有一个包含所有包含的文件夹。

    【讨论】:

    • 抱歉,您的意思是在我的路径中添加/opt/boxen/homebrew/Cellar/mpg123/1.15.4/include/ 吗?那么我是否必须为所需的每个 C 扩展都这样做,因为我也遇到了与 portaudio 类似的问题...
    • 在默认的自制软件安装(到/usr/local)中,它会创建一个/usr/local/include 文件夹。这也应该在/opt/boxen/homebrew/include 中为您提供。此文件夹包含指向包的各个 include 目录的符号链接。
    • 我试了一下,但没有骰子,这是我的输出作为要点:gist.github.com/petems/6812615
    • 它可能有一个特殊的开发头包。
    • 我认为这将是解决方案,但即使在我的命令行前面显式添加 INCLUDE=/usr/local/include 它仍然假装找不到它的标题......跨度>
    【解决方案2】:

    我在尝试安装 audite 时遇到了同样的问题。事实证明,mkmf 编写了一个名为 mkmf.log 的文件,以更具体地告诉您它如何确定标头是否可用:

     >>> cat mkmf.log
    have_header: checking for mpg123.h... -------------------- no
    
    "xcrun cc -E -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin12.0 -I.  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE     -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common    conftest.c -o conftest.i"
    xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.
    checked program was:
    /* begin */
    1: #include <mpg123.h>
    /* end */
    
    --------------------
    

    原来我还没有安装 xcode;安装并运行后

    xcode-select --print-path
    

    我看到现在已经设置了路径。然后我仍然必须运行一次 xcrun 以同意 Apple 的许可协议,但安装后安装就好了!

    【讨论】:

    • 不幸的是没有骰子,但该日志文件很有用:gist.github.com/petems/7791532
    • 好奇!也许尝试创建一个 /usr/var/lib 目录并将其软链接到 /var/lib ?
    • 你能解决这个问题吗?我也有类似的问题。
    • @StefanNovak:是的,正如我在帖子中解释的那样,安装 xcode 和 xcrun 就可以了。
    【解决方案3】:
    xcode-select --install
    

    帮我解决了。

    【讨论】:

      【解决方案4】:

      所以最后以下其中一项为我解决了问题,我不确定是哪一项,因为自从我遇到这个问题以来,我已经重建并更换了几次我的机器:

      • 切换到 Ruby 2.0.0
      • 升级到 Mavericks(确实改变了一些 我相信有 xcode 的东西)
      • 将我的 Boxen/Brew 更新到最新版本 版本

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-14
        • 1970-01-01
        • 2011-04-19
        相关资源
        最近更新 更多