From: "Ara.T.Howard" Date: 2004-08-20T04:45:59+09:00 Subject: use LD_RUN_PATH with extension - [WAS] Re: require and LD_LIBRARY_PATH On Fri, 20 Aug 2004 jim@freeze.org wrote: > So, I assume that > > ENV['LD_LIBRARY_PATH'] = "/disk2/jfn/user/local/lib" > > is only setting a shell variable and not exporting it to the > environment. > > Is this correct? If so, how do I export this variable? i don't remember this - but it looks as if you are correct: jib:~ > ruby a.rb ------------------------------------------------------------------------------- LD_LIBRARY_PATH ------------------------------------------------------------------------------- # ------------------------------------------------------------------------------- LD_RUN_PATH ------------------------------------------------------------------------------- ruby rocks jid:~ > cat a.rb require 'tmpdir' require 'rbconfig' require 'fileutils' $VERBOSE=nil def run cmd system "#{ cmd } >/dev/null 2>&1" status = $?.exitstatus raise "cmd <#{ cmd }> failed with <#{ status }>" unless status == 0 status end # # setup # ruby = File.join(*Config::CONFIG.values_at('bindir','RUBY_INSTALL_NAME')) Dir.chdir Dir.tmpdir tmp = File.join(Dir.tmpdir, 'tmp') FileUtils.mkdir_p tmp at_exit{ FileUtils.rm_rf tmp } barfoo_c = File.join tmp, 'barfoo.c' barfoo_so = File.join tmp, 'libbarfoo.so' foobar_c = 'foobar.c' foobar_so = 'foobar.so' extconf_rb = 'extconf.rb' # # make barfoo.c # src = <<-txt #include #include void barfoo(){ printf("ruby rocks\\n"); } txt open(barfoo_c,'w'){|f| f.write src } at_exit{ FileUtils.rm_f barfoo_c } # # make barfoo.so # run "gcc -o #{ barfoo_so } -shared #{ barfoo_c }" at_exit{ FileUtils.rm_f barfoo_so } # # make foobar.c # src = <<-txt #include "ruby.h" void Init_foobar(){ barfoo(); } txt open(foobar_c,'w'){|f| f.write src} at_exit{ FileUtils.rm_f foobar_c } # # make extconf.rb # src = <<-txt require 'mkmf' dir_config 'barfoo' find_library 'barfoo', 'barfoo', '#{ tmp }' create_makefile 'foobar' txt open(extconf_rb,'w'){|f| f.write src} at_exit{ FileUtils.rm_f extconf_rb } run "#{ ruby } #{ extconf_rb } --with-barfoo-lib=#{ tmp }" at_exit{ FileUtils.rm_f 'Makefile' } # # make foobar.so # run "make" at_exit{ FileUtils.rm_f foobar_so } # # try foobar.so with LD_LIBRARY_PATH # fork do begin puts('-' * 79) puts 'LD_LIBRARY_PATH' puts('-' * 79) ENV['LD_LIBRARY_PATH'] = tmp require 'foobar' rescue LoadError => le p le ensure exit! end end Process.wait # # try foobar.so after rebuilding with LD_RUN_PATH # fork do begin puts('-' * 79) puts 'LD_RUN_PATH' puts('-' * 79) run "rm foobar.so && LD_RUN_PATH=#{ tmp } make" require 'foobar' rescue LoadError => le p le ensure exit! end end Process.wait -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================