views:

3245

answers:

3

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?

A: 

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).
cite
Thank you for the response. I found the /tmp/.ruby_inline/ directory in my app and blew it away, uninstall the RubyInline and image_science gems, and port uninstalled freeimage. Then reinstalled the gems as x86_64 and port reinstalled freeimage (3.12.0_0). I still got the error.What is strange, is even with all of those gems and ports uninstalled, I restarted the server and loaded a page and the same "mach-o" error came up.
Mighty
Did you investigate the executable (i.e., native) parts of those two gems as I sugested? Did you campre the output to, e.g., the rails binary?
cite
Sorry, probably a bit of a noob here when it comes to this, but I found where the gems are stored (/usr/local/lib/ruby/gems/1.8) and found the RubyInline and image_science directory and found several files in /lib and /bin, but they are all .rb files, which I assume aren't the executable files. I did the "file" examination of them and the obviously came back as "-w script text executable." I must be missing something...
Mighty
Ok, I found a little more info. I was able to examine an ImageScience executable file and determine that it is i386, but it wasn't in the gems directory, it was here: /config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.bundle. I blew the whole .ruby_inline/ away, reinstalled everything again and it still doesn't work.
Mighty
Sorry, still struggling with this...So after port-uninstalling free_image, and gem-uninstalling RubyInline and image_science, I wanted to see what the error would be:[I have to post the error in a separate comment below. Ran out of chars here...]I don't know if there is anything to glean from this, but I did notice references to the i386 arch even BEFORE any of the relevant add-ons were installed. This leads me to believe that there are other gems/ruby infrastructure that aren't running at 64-bit, which may be causing problems.Anyone have any thoughts on this?
Mighty
ld: library not found for -lfreeimagecollect2: ld returned 1 exit statusProblems loading ImageScienceProcessor: error executing "cc -arch i386 -pipe -bundle -undefined dynamic_lookup -I/opt/local/include -fno-common -arch i386 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -I /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I
Mighty
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/include -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -o \"app/config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.bundle\" \"/app/config/tmp/.ruby_inline/Inline_ImageScience_cdab.c\" -L/opt/local/lib -lfreeimage -lfreeimage -lstdc++ ": 256Renamed /app/config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.c to /app/config/initializers/../tmp/.ruby_inline/Inline_ImageScience_cdab.c.bad
Mighty
Two things strike me as odd: (1) Hte build process for ImageScience explicitely mentioning "i386" instead of "x86_64" and second, the freeimage library not being found.
cite
Figured it out. I had "i386" in my bash profile. Once I changed it to: "export ARCHFLAGS='-arch x86_64'" it works. Ugh. Thank you so much for your help.
Mighty
+1  A: 

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}`}
Colins
A: 

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
alex