Having trouble getting iconv-0.5 working on OS X

Hi,

···

At Tue, 8 Apr 2003 10:34:53 +0900, Sam Roberts wrote:

$ ruby -r iconv -e ‘Iconv.iconv(“iso-8859-1”,“utf-8”, “hello”)’
dyld: ruby Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
Trace/BPT trap

It seems that ruby isn’t finding my /usr/local/lib/libiconv.dylib at
runtime, but I’m stumped as to how to convince it to look harder!

I don’t know about Mac OS X, but that libiconv seems
non-standard library, right? If so, I suspect you might need
to add /usr/local/lib to runtime library path.


Nobu Nakada

I think so, too, but I've no idea how. The only thing I can think of is
this:

$ DYLD_LIBRARY_PATH=/usr/local/lib ruby -r iconv -e 'Iconv.iconv("iso-8859-1","utf-8", "hello")'
dyld: ruby Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
Trace/BPT trap

dyld (the dynamic loader, apparently), suggested the name of the env
variable. I'll keep hacking away at this.

Thanks,
Sam

Quoteing nobu.nokada@softhome.net, on Tue, Apr 08, 2003 at 11:33:47AM +0900:

···

At Tue, 8 Apr 2003 10:34:53 +0900, > Sam Roberts wrote:
> $ ruby -r iconv -e 'Iconv.iconv("iso-8859-1","utf-8", "hello")'
> dyld: ruby Undefined symbols:
> _libiconv
> _libiconv_close
> _libiconv_open
> Trace/BPT trap
>
> It seems that ruby isn't finding my /usr/local/lib/libiconv.dylib at
> runtime, but I'm stumped as to how to convince it to look harder!

I don't know about Mac OS X, but that libiconv seems
non-standard library, right? If so, I suspect you might need
to add /usr/local/lib to runtime library path.

--
Nobu Nakada

The error turned out to be deceptively simple. extconf.rb fails to find
iconv() in -liconv, though it is there.

Any idea why extconf.rb thinks iconv() isn’t in -liconv, and why on earth does
it both ignore the fact that it can’t find iconv(), and then disables the
linker’s warning that it couldn’t find iconv()?

It first fails to find iconv in libiconv.a:

[ensemble] ~/p/ruby/download/iconv-0.5 $ ruby extconf.rb
checking for iconv.h… yes
checking for iconv() in -liconv… no
checking for rb_obj_freeze()… yes
checking for rb_block_given_p()… yes
checking for rb_str_buf_new()… no
creating Makefile

Note that it found /usr/local/include/iconv.h, but failed to find iconv(), and
yet still created the Makefile. Why?

Makefile then builds iconv.bundle, but doesn’t link it against an iconv library, and
appears to have disabled all linker warnings. This, of course, doesn’t work:

[ensemble] ~/p/ruby/download/iconv-0.5 $ touch iconv.c; make; ruby -I. -r iconv -e Iconv.iconv
gcc -fno-common -g -Os -pipe -no-cpp-precomp -pipe -pipe -no-precomp -I. -I/usr/lib/ruby/1.6/powerpc-darwin6.0 -I. -I/usr/include -DHAVE_ICONV_H -DHAVE_RB_OBJ_FREEZE -DHAVE_RB_BLOCK_GIVEN_P -c -o iconv.o iconv.c
gcc: unrecognized option `-no-precomp’
cc1: warning: changing search order for system directory “/usr/include”
cc1: warning: as it has already been specified as a non-system directory
cc -dynamic -bundle -undefined suppress -flat_namespace -L/usr/lib/ruby/1.6/powerpc-darwin6.0 -L/usr/lib -o iconv.bundle iconv.o
dyld: ruby Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
Trace/BPT trap

Adding -liconv back into the link path works fine:

[ensemble] ~/p/ruby/download/iconv-0.5 $ touch iconv.c; make LOCAL_LIBS=-liconv; ruby -I. -r iconv -e Iconv.iconv
gcc -fno-common -g -Os -pipe -no-cpp-precomp -pipe -pipe -no-precomp -I. -I/usr/lib/ruby/1.6/powerpc-darwin6.0 -I. -I/usr/include -DHAVE_ICONV_H -DHAVE_RB_OBJ_FREEZE -DHAVE_RB_BLOCK_GIVEN_P -c -o iconv.o iconv.c
gcc: unrecognized option -no-precomp' cc1: warning: changing search order for system directory "/usr/include" cc1: warning: as it has already been specified as a non-system directory cc -dynamic -bundle -undefined suppress -flat_namespace -L/usr/lib/ruby/1.6/powerpc-darwin6.0 -L/usr/lib -o iconv.bundle iconv.o -liconv -e:1:in iconv’: wrong # of arguments (0 for 2) (ArgumentError)
from -e:1

Thanks,
Sam

Quoteing sroberts@uniserve.com, on Tue, Apr 08, 2003 at 12:51:08PM +0900:

···

I think so, too, but I’ve no idea how. The only thing I can think of is
this:

$ DYLD_LIBRARY_PATH=/usr/local/lib ruby -r iconv -e ‘Iconv.iconv(“iso-8859-1”,“utf-8”, “hello”)’
dyld: ruby Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
Trace/BPT trap

dyld (the dynamic loader, apparently), suggested the name of the env
variable. I’ll keep hacking away at this.

Thanks,
Sam

Quoteing nobu.nokada@softhome.net, on Tue, Apr 08, 2003 at 11:33:47AM +0900:

At Tue, 8 Apr 2003 10:34:53 +0900, > > Sam Roberts wrote:

$ ruby -r iconv -e ‘Iconv.iconv(“iso-8859-1”,“utf-8”, “hello”)’
dyld: ruby Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
Trace/BPT trap

It seems that ruby isn’t finding my /usr/local/lib/libiconv.dylib at
runtime, but I’m stumped as to how to convince it to look harder!

I don’t know about Mac OS X, but that libiconv seems
non-standard library, right? If so, I suspect you might need
to add /usr/local/lib to runtime library path.


Nobu Nakada