5

Just did a fresh install of ruby 1.8.7 REE and MRI on a machine with fresh gem sets (Using RVM) Yet in each of them when I try to use memprof i get this error

$ gem install memprof
$ irb
>> require 'rubygems'
>> require 'memprof'
>> LoadError: dlopen(/Users/schneems/.rvm/gems/ruby-1.8.7-p352@test/gems/memprof-0.3.10/lib/memprof.bundle, 9): Symbol not found: __mh_bundle_header
  Referenced from: /Users/schneems/.rvm/gems/ruby-1.8.7-p352@test/gems/memprof-0.3.10/lib/memprof.bundle
  Expected in: flat namespace
 in /Users/schneems/.rvm/gems/ruby-1.8.7-p352@test/gems/memprof-0.3.10/lib/memprof.bundle - /Users/schneems/.rvm/gems/ruby-1.8.7-p352@test/gems/memprof-0.3.10/lib/memprof.bundle
    from /Users/schneems/.rvm/gems/ruby-1.8.7-p352@test/gems/memprof-0.3.10/lib/memprof.bundle
    from /Users/schneems/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `require'
    from (irb):2

The error is Symbol not found: __mh_bundle_header. My question is this: what do i need to do to get my system to find this symbol, or is there something else I need to install? Any debugging suggestions welcomed.

Schneems
  • 14,918
  • 9
  • 57
  • 84

2 Answers2

3

This is what I did to get it to work on Snow Leopard:

cd ..../gems/memprof-0.3.10/ext/

Edit Makefile, search for LD_SHARED=

Change from

LDSHARED = cc -arch x86_64 -dynamiclib -undefined suppress -flat_namespace

to

LDSHARED = cc -arch x86_64 -bundle -bundle_loader $(RUBY) -undefined suppress -flat_namespace

(replaced -dynamiclib with -bundle and -bundleloader options)

Then,

make install (which creates memprof.bundle and copies it to memprof*/lib)

Edit: Just to clarify, $(RUBY) must contain the full pathname to the ruby interpreter (the executable). Under RVM, the Makefile initializes it to the appropriate interpreter, so the above line works without a problem.

Sriram Srinivasan
  • 1,255
  • 17
  • 16
  • thanks for the reply, i'll try it out as soon as i get a chance. What exactly is the change above doing? – Schneems Nov 05 '11 at 21:02
  • 2
    -bundle creates a bundle, a mac-specific dynamic library format. The memprof bundle has references to symbols in the host program, the ruby interpreter. The -bundle_loader option points to the particular executable that is going to load this bundle. – Sriram Srinivasan Nov 05 '11 at 21:42
1

Looks like it was not compiled correctly and was missing the linker flags for the bundle library. Try building it was LDFLAGS="-bundle"... I'm not sure how you do that with RVM, but I assume it will inherit the environment you give it.

EDIT | Sorry, looks like the correct ld flag may be: LDFLAGS="-bundler_loader" EDIT 2 | Actually, I'm not sure if it's bundle or bundle_loader... I'm seeing both in Google results.

d11wtq
  • 34,788
  • 19
  • 120
  • 195
  • I tried using `rvm export` with both flags and i'm still getting the error. Maybe thats not the right command? – Schneems Oct 26 '11 at 22:43
  • `rvm export` seems to be for managing gemsets, not for changing compile settings. First try removing memprof, then do `LDFLAGS="-bundle" gem install memprof`, and if that doesn't work, try building ruby the same way (with LDFLAGS set)... it's not clear from the backtrace which is trying to use bundle. I think it's actually ruby when trying to load the gem itself. – d11wtq Oct 26 '11 at 23:22
  • tried `LDFLAGS="-bundle" gem install memprof` and also `LDFLAGS="-bundle" rvm install 1.8.7` and neither worked. – Schneems Oct 27 '11 at 17:24