From: Brian Candler Date: 2009-04-30T04:38:43+09:00 Subject: Re: Ruby Interface of Erlang Brian Candler wrote: > BTW, I haven't been able to get it to build yet - it's stuck looking for > -lei I found the problem. In configure.rb I had to add "-pthread" to --with-ldflags. Without that, mkmf.log was showing the following errors: "gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-linux -I./src -I/usr/lib/erlang/lib/erl_interface-3.5.7/include -g -O2 conftest.c -L'.' -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -L'/usr/lib/erlang/lib/erl_interface-3.5.7/lib' -Wl,-R'/usr/lib/erlang/lib/erl_interface-3.5.7/lib' -lei -lerl_interface -lruby-static -lei -ldl -lcrypt -lm -lc" /usr/lib/erlang/lib/erl_interface-3.5.7/lib/libei.a(ei_pthreads.o): In function `__erl_errno_place': (.text+0x4c): undefined reference to `pthread_once' /usr/lib/erlang/lib/erl_interface-3.5.7/lib/libei.a(ei_pthreads.o): In function `__erl_errno_place': (.text+0x7a): undefined reference to `pthread_getspecific' /usr/lib/erlang/lib/erl_interface-3.5.7/lib/libei.a(ei_pthreads.o): In function `__erl_errno_place': (.text+0xa4): undefined reference to `pthread_setspecific' /usr/lib/erlang/lib/erl_interface-3.5.7/lib/libei.a(ei_pthreads.o): In function `__erl_errno_place': (.text+0xb6): undefined reference to `pthread_getspecific' /usr/lib/erlang/lib/erl_interface-3.5.7/lib/libei.a(ei_pthreads.o): In function `erl_errno_key_alloc': (.text+0x136): undefined reference to `pthread_key_create' /usr/lib/erlang/lib/erl_interface-3.5.7/lib/libei.a(ei_pthreads.o): In function `ei_m_trylock': (.text+0x189): undefined reference to `pthread_mutex_trylock' collect2: ld returned 1 exit status However, even after successful compilation, it still didn't work due to a runtime linker error on "__erl_errno": irb(main):001:0> require 'erlix' LoadError: /usr/local/lib/ruby/site_ruby/1.8/i686-linux/erlix.so: undefined symbol: __erl_errno - /usr/local/lib/ruby/site_ruby/1.8/i686-linux/erlix.so from /usr/local/lib/ruby/site_ruby/1.8/i686-linux/erlix.so from (irb):1 After poking around header files, I decided that the way to fix this was: $ make clean $ make CPPFLAGS=-D_REENTRANT And it happily builds and runs the sample now. I don't know how configure.rb should decide for itself whether -D_REENTRANT is needed or not. A few more suggestions: (1) For converting objects to strings, you should implement a "to_s" method, not "puts". Current behaviour is rather un-rubylike: irb(main):008:0> t=ErlixTuple.new([a1,f,b,a2,i]) => # irb(main):009:0> t => # irb(main):010:0> t.puts ## unexpected {atom1,17.000000,#Bin,atom2,101} => nil irb(main):011:0> t.to_s => "#" ## unexpected This would also allow you to interpolate terms into strings, e.g. puts "The response was #{t}" (2) It would be helpful if ErlixTurple took a variable number of arguments, instead of a single array. That would let you write ErlixTuple.new(a1,f,b,a2,i) This wouldn't prevent you from using an array if you like, because Ruby provides a 'splat' operator: arr = [a1,f,b,a2,i] ErlixTuple.new(*arr) Anyway, keep up the good work - this is looking promising! Regards, Brian. -- Posted via http://www.ruby-forum.com/.