From: Mauricio Fernandez Date: 2007-10-19T04:18:23+09:00 Subject: Re: rocaml 0.6.0: fast, easy Ruby extensions in Objective Caml On Fri, Oct 19, 2007 at 03:30:06AM +0900, Daniel Berger wrote: > On Oct 18, 12:09 pm, Mauricio Fernandez wrote: > > I'm sorry for all the issues and appreciate your patience. The basic problem > > is that I'm using Debian and everything Just Works(TM) with its OCaml > > packages, so it is harder for me to anticipate problems like those you ran > > into. I see that you're using Solaris, which adds further uncertainty because > > I'm not sure its linker can build shared objects with non-PIC code [1]. Some > > magic incantations in the form of $LDFLAGS might be required. You're stepping > > on new ground :) > > It would seem so. Your one line patch to rocaml_extconf.rb worked > (thanks!), but now I get this: > > irb(main):002:0> require 'foo' > LoadError: ld.so.1: ruby: fatal: relocation error: file /export/home/ > djberge/src/ruby/rocaml-0.6.1/foo.so: symbol __muldi3: referenced > symbol not found - /export/home/djberge/src/ruby/rocaml-0.6.1/foo.so > from /export/home/djberge/src/ruby/rocaml-0.6.1/foo.so > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:27:in `require' > from (irb):2 It seems we're almost there (we went through the critical non-PIC code relocation phase :-) According to google, __muldi3 is an internal GCC library function. Do you have a native linker in addition to GCC's? GCC's will automatically link against libgcc, but it seems that's not the case with the native one. At any rate, linking against either libgcc.a or libgcc_s.so.1 should work; something like this maybe? diff -rN -u -w old-rocaml/rocaml_extconf.rb new-rocaml/rocaml_extconf.rb --- old-rocaml/rocaml_extconf.rb 2007-10-18 21:03:41.000000000 +0200 +++ new-rocaml/rocaml_extconf.rb 2007-10-18 21:03:41.000000000 +0200 @@ -89,7 +89,9 @@ # needed by mkmf's create_makefile $LOCAL_LIBS = "#{CAML_TARGET} #{ocaml_native_lib_path}/libasmrun.a #{extra_caml_libs.join(" ")}" - +# try to add GCC's libgcc, required on Sparc +libgcc = Dir["/lib/libgcc*"].first # maybe some other search path(s) +$LOCAL_LIBS << " " << libgcc if libgcc # determine whether camlp4 (or camlp5) can be used: You might have to change the search path. On my platform, libgcc can also be found in /usr/lib/gcc/i486-linux-gnu/. Linking against either libgcc.a or libgcc_s.so should do. I haven't pushed the patch yet; want to know if /lib/libgcc* is OK or if the path needs to be changed. Also, can I rely on say require 'rbconfig' libgcc_needed = Config::CONFIG["arch"] =~ "sparc" ? > Oh, and these warnings showed up during the build. Dunno if you're > interested: > > "foo_rocaml_wrapper.c", line 61: warning: statement not reached > "foo_rocaml_wrapper.c", line 68: warning: statement not reached > "foo_rocaml_wrapper.c", line 338: warning: statement not reached These are all things like rb_raise(klass, "%s", s); return Qnil; /* not reached */ or if(exception == Qnil && !status) { return ret; } else if(status) { /* exception in Ruby -> caml conversions */ rb_jump_tag(status); } else { /* OCaml exception*/ rb_raise(rb_eStandardError, StringValuePtr(exception)); } return Qnil; /* never reached */ It seems your GCC is smarter than mine and knows that rb_raise, rb_jump_tag, etc. do not return. Know any macros in ruby.h to handle such things? They are harmless and can be safely ignored anyway. -- Mauricio Fernandez - http://eigenclass.org