未能安装pg gem,“mkmf.rb找不到ruby的头文件” (Mac OSX 10.6.5) [英] Failing installing pg gem, "mkmf.rb can't find header files for ruby" (Mac OSX 10.6.5)

查看:1009
本文介绍了未能安装pg gem,“mkmf.rb找不到ruby的头文件” (Mac OSX 10.6.5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级到Rails 3,并对MacPorts,宝石和数据库进行了一些整理。我扔出所有的宝石,并安装新鲜。除了pg gem的要求,一切似乎都没有问题。



在为PostgreSQL创建一个新的Rails 3项目后,服务器无法启动,抱怨缺少宝石宝石。做捆绑安装,它突然停了一段时间,当然,在pg gem上失败。

 使用本机扩展安装pg(0.10.0)/Library/Ruby/Site/1.8/rubygems/installer.rb:483:in`build_extensions':错误:无法构建gem本机扩展。 (Gem :: Installer :: ExtensionBuildError)

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can not在/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h


找到ruby头文件/ Gem文件将保持安装在/ Library /Ruby/Gems/1.8/gems/pg-0.10.0进行检查。
从/Library/Ruby/Site/1.8/rubygems/installer.rb:446记录到/Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
的结果:来自/Library/Ruby/Site/1.8/rubygems/installer.rb:446:in`每个'
/从/Library/Ruby/Site/1.8/rubygems/installer.rb开始的`build_extensions'
:198:在`install'中
从/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/source.rb:95:in`install'$ from / Library /Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:55:从`/Library/Ruby/Gems/1.8/gems/bundler-1.0.7'运行
/lib/bundler/spec_set.rb:12:in从'/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in'每个'
' '从/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in'运行'
从/Library/Ruby/Gems/1.8运行'
/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in从/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/cli安装
.rb:225:在`install'
中/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in`send'
from /Library/Ruby/Gems/1.8/gems /bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:从`/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler'运行'
/vendor/thor/invocation.rb:118:in`invoke_task'$ / $ / bibrary/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in从/ Library中从`/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in`start'
`派发'
/Ruby/Gems/1.8/gems/bundler-1.0.7/bin/bundle:13 $ b $ from / usr / bin / bundle:19:在load中
from / usr / bin / bundle: 19

我在论坛和博客上发现的最常见建议是(重新)安装XCode开发人员工具。他们已经在那里了,但我仍然重新安装了它们,结果没有上面那么好。



其中ruby 表示 / usr / bin / ruby​​ ruby​​ -v ruby​​ 1.8.7(2009) -06-12 patchlevel 174)[universal-darwin10.0] ,如果有任何线索。



欢迎使用指针。任何缺失的信息,将有助于搞清楚这一点,我会很乐意并及时提供!






自DVD下载XCode据说版本会被破坏,而且事情会变好一段时间。

  > sudo env ARCHFLAGS = -  arch i386bundle install 

事情似乎很顺利,直到开始Rails barfed说:

  /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext。 bundle:dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle,9):找不到合适的图像。找到了:(LoadError)
/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle:mach-o,但是架构错误 - /Library/Ruby/Gems/1.8/ gems / pg-0.10.0 / lib / pg_ext.bundle

为了解决任何问题,我尝试了 bundle install ,其中archflags设置为 -arch x86_64 ,但效果并不理想:

  ***您的PostgreSQL安装似乎没有与正在运行的ruby解释器相同的架构([] vs [x86_64])
我会继续,但如果失败,请尝试设置ARCHFLAGS。
[...]
找不到PostgreSQL客户端库(libpq)
*** extconf.rb失败***

libpq是我现在必须通过某些标志提供路径的东西吗?或者我完全出去吃午餐?

解决方案

一般来说,Postgres的gem bundle想要知道 pg_config 正在隐藏,所以他们可以询问Postgres的安装情况。



使用 locate pg_config 看看你的Mac是否知道它隐藏的地方。



我使用

  /Applications/mappstack-1.2- 3 / postgresql / bin / pg_config 

另一个位于:

  /Library/PostgreSQL/9.0/bin/pg_config 

我不记得在 /Library/PostgreSQL/9.0 中安装它,所以它可能已经由Snow Leopard预安装,或者我在受影响的情况下工作量太大,可能使用

一旦找到 pg_config 尝试将该目录添加到PATH的开头,然后重新运行gem install。
或使用:

pre $ export $ SQL $ PATH = -with-pg-config = $ SQL_PATH / bin / pg_config

并尝试安装。如果这些工作中的任何一个都完成了。否则......

安装程序可能需要的下一件事是访问Postgres头文件,因此您可以查看 bin 目录,并查看是否可以找到 include 目录。

然后,在该目录中查找 lib 目录。一旦你知道了这些位置,你就应该拥有设置你的环境变量来完成安装程序所需的一切。您需要阅读安装程序的 README INSTALL 文件并查看需要设置的内容。您将进行配置:

  export include_dir = $ SQL_PATH / include / 
export lib_dir = $ SQL_PATH / lib /
gem install pg - --with-pgsql-include-dir = $ include_dir --with-pgsql-lib-dir = $ lib_dir

希望这会有所帮助。我有Rails 3和我的Postgres运行正常,使用mappstack Postgres和EnterpriseDB版本,所以上面的信息应该可以帮到你。


I just upgraded to Rails 3 and had a bit of a mess with MacPorts, gems and databases to sort out. I threw out all the gems and installed them fresh. Everything seems to be OK except for the requirement of the pg gem.

After creating a new Rails 3 project, prepared for PostgreSQL, the server would not start, complaining about the missing pg gem. Doing bundle install, it chugged along for a while and, of course, fails on the pg gem.

Installing pg (0.10.0) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.10.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
    from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
    from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
    from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/source.rb:95:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:55:in `run'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in `run'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/cli.rb:225:in `install'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `send'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.7/bin/bundle:13
    from /usr/bin/bundle:19:in `load'
    from /usr/bin/bundle:19

The most common suggestion I have found on forums and blogs is to (re)install the XCode developer tools. They were already there, but I reinstalled them anyway, with no better outcome than the above.

which ruby says /usr/bin/ruby, and ruby -v says ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0], if there's any clue there.

Pointers are welcome. Any missing information that would help figuring this out, I'll gladly and promptly provide!


I downloaded XCode since the DVD version is said to be broken and things went better for a while. bundle install started talking about "archflags" instead, so I did:

sudo env ARCHFLAGS="-arch i386" bundle install

and things seemed to go fine, until starting Rails barfed, saying:

/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle, 9): no suitable image found.  Did find: (LoadError)
    /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle

Grappling for anything, I tried bundle install with archflags set to -arch x86_64, but it didn't go well:

*** Your PostgreSQL installation doesn't seem to have an architecture in common with the running ruby interpreter ([] vs. ["x86_64"])
I'll continue anyway, but if it fails, try setting ARCHFLAGS.
[...]
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***

Is libpq something I now have to supply a path to via some flags? Or am I completely out to lunch?

解决方案

Generally the gem bundles for Postgres want to know where pg_config is hiding so they can ask about the Postgres installation.

Use locate pg_config to see if your Mac knows where it's hiding.

I installed a copy of Postgres using mappstack, so my Mac says there's a copy at:

/Applications/mappstack-1.2-3/postgresql/bin/pg_config

and another at:

/Library/PostgreSQL/9.0/bin/pg_config

I don't remember installing the one at /Library/PostgreSQL/9.0, so it might have been preinstalled by Snow Leopard, or I did it when under the influence of too much work, possibly using the Postgres installer from EnterpriseDB.

Once you've found the location of pg_config try adding that directory to the start of your PATH and then rerun the gem install. Or use:

export SQL_PATH=/Library/PostgreSQL/9.0
gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config

and try installing. If either of those work you're done. Otherwise...

The next thing the installers might want are access to the Postgres headers, so you look in the parent of the bin directories, and see if you can find an include directory.

After that, look in that directory for a lib directory. Once you know those locations you should have all you need to set your environment variables to let the installer complete. You'll need to read the README or INSTALL file of the installer and see what needs to be set up. You'll be configuring:

export include_dir=$SQL_PATH/include/
export     lib_dir=$SQL_PATH/lib/
gem install pg -- --with-pgsql-include-dir=$include_dir --with-pgsql-lib-dir=$lib_dir

Hopefully that'll all help. I have Rails 3 and my Postgres running fine, using the mappstack Postgres and the EnterpriseDB versions, so the above info should get you there.

这篇关于未能安装pg gem,“mkmf.rb找不到ruby的头文件” (Mac OSX 10.6.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆