Snow Leopard / 64-bit ruby gem problem?

本秂侑毒 提交于 2019-12-21 06:05:33

问题


I just upgraded to Snow Leopard, including installing the new XCode, re-compiled Ruby 1.8 and MySQL. My Rails app is running fine in the updated environment, except for some image processing features, which depend on ImageScience/FreeImage.

I upgraded MacPorts to 1.8, removed all previously installed ports and reinstalled them in 1.8, which I assume would have installed a 64-bit versions of the ports, including FreeImage. I also re-installed the image_science and RubyInline as 64-bit gems using:

sudo env ARCHFLAGS="-arch x86_64" gem install RubyInline image_science

Now when I run my app on pages that require image processing I get this error in my log:

Problems loading ImageScienceProcessor: dlopen(/myappname/config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.bundle, 9): no suitable image found. Did find: /myappname/config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.bundle: mach-o, but wrong architecture - /myappname/config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.bundle

Can someone help me out as to what this error is telling me?


回答1:


It reports that it tried to execute some native code, which was in the right executable format, but for the wrong architecture. This probably means that there is either still a mismatch between the gem version and the running kernel, or that some temporary code which was created when you still had your old operating system installed is still there. Two possible solutions might be:

  1. Make a backup of your application, find the offending ".ruby_inline" directory and delete it, then try again.
  2. Find out where the "RubyInline" and "image_science" gems are installed (e.g. gem list -d image_science) and check that their native parts (usually those within gems//lib or something similar, those in "bin" or those with a ".so" extension) match your kernel. You can use the "file" tool to examine whether a file is a 32 or 64 bit executable (simply call file filename).



回答2:


I had the same problem that some gem dependencies (especially the C based ones) needed to be reinstalled for the 64 bit (snow leopard) environment. I used the ruby console for this. Here's what I did:

$ irb
  irb> `gem list`.each_line {|line| `sudo env ARCHFLAGS="-arch x86_64" gem install #{line.split.first}`}



回答3:


After doing what colins peters mentioned above (the code to reinstall 64-bit gems), I also had to change the directory where my IDE is looking for gems. Since RubyMine didn't do it for me, or I didn't find it, I did this:

cd ~/.gem/ruby/1.8/
rm -r gems
ln -s /Library/Ruby/Gems/1.8/gems gems



回答4:


I recently had a similar issue where rails was throwing the "but wrong architecture no suitable image found" error when starting rails console or the rails server.

Running file on the associatd .dylib files, and the gem, generally returned either an applicable x86_64 version, or a universal which included it. Eventually, I traced it back to the actual version of Ruby I was running. The /usr/bin/ruby executable itself was only i386 compatible. This was really a shocker, as I assumed the new xcode and osx 10.7 would have brought me a 64 bit ruby.

Using RVM, I installed another instance of ruby (again 1.8.7). Doing this required that I install a new instance of readline (for which I used homebrew, : brew install readline) and installed the rvm with rvm install 1.8.7 --with-readline-dir=/usr/local/Cellar/readline/6.2.1/.

After doing this, and switching to use my new ruby instance (rvm use 1.8.7), all my gems were gone (the RVM install somehow changed my default gem_path.) gem install rake, followed by gem install bundler, and then bundle install got me up and running.

Long story short, make sure your ruby executable matches the instruction-set version that your ruby/rails packages are were built in.



来源:https://stackoverflow.com/questions/1367380/snow-leopard-64-bit-ruby-gem-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!