Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libiconv and MacOS

I am trying to compile GCC 4.5.1 in Mac OS X Lion.

I have a problem with libiconv. First it complained about undefined symbols for architecture x86_64, which were: _iconv, _iconv_open and _iconv_close. I found out that MacPorts version of libiconv rename those to: _libiconv, _libiconv_open and _libiconv_close. So I linked to the Mac OS native libiconv in /usr/lib instead of the MacPorts library in /opt/local/lib.

Undefined symbols for architecture x86_64:
"_iconv", referenced from:
  _convert_using_iconv in libcpp.a(charset.o)
  __nl_find_msg in libintl.a(dcigettext.o)
 (maybe you meant: __cpp_destroy_iconv, _cpp_init_iconv )
"_iconv_close", referenced from:
  __cpp_destroy_iconv in libcpp.a(charset.o)
  __cpp_convert_input in libcpp.a(charset.o)
  __nl_free_domain_conv in libintl.a(loadmsgcat.o)
"_iconv_open", referenced from:
  _init_iconv_desc in libcpp.a(charset.o)
  __nl_init_domain_conv in libintl.a(loadmsgcat.o)

However, after doing that, I tried to rebuild it from the beginning (cleaning and everything), but then it complained at a different point about undefined symbols, but this time _libiconv, _libiconv_open and _libiconv_close.

Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
    _identifier_to_locale in libbackend.a(pretty-print.o)
  "_libiconv_close", referenced from:
    _identifier_to_locale in libbackend.a(pretty-print.o)
  "_libiconv_open", referenced from:
    _identifier_to_locale in libbackend.a(pretty-print.o)

Is there any idea about how I can deal with this? I have found some solutions uninstalling libiconv from MacPorts, but I don't want to do it, as I have many ports depending on it.

like image 858
Javier Moreno Avatar asked Sep 27 '12 10:09

Javier Moreno


People also ask

What does libiconv do?

Description. LibIconv converts from one character encoding to another through Unicode conversion (see Web page for full list of supported encodings).


3 Answers

I solved it by:

$ sudo port -f deactivate libiconv
$ ...build my project...
$ sudo port activate libiconv

There's probably a better way but I'm not using GCC directly, so this helps as a temporary workaround.

like image 83
Erik Kaplun Avatar answered Oct 22 '22 21:10

Erik Kaplun


I solve this by including two libiconv from both /usr/lib and /opt/local/lib. This is a hacky way to solve, if anyone has better solution, please post. Suppose [gcc-src] is the source directory of gcc. What I did is as following:

  1. In /usr/lib, copy libiconv.* as libiconv1.*
  2. Go to [gcc-src]/gcc/Makefile.in
    change LIBINTL = @LIBINTL@ to LIBINTL = @LIBINTL@ -L/opt/local/lib -liconv -L/usr/lib -liconv1
  3. Configure by: CC=gcc-mp-4.7 CXX=g++-mp-4.7 ../gcc-4.7.2/configure --with-gmp=/opt/local --enable-languages=c,c++ --enable-checking=release —prefix=[gcc-src] <- must be absolute address. I use a macport-made gcc and g++. Maybe using gcc and g++ from system work too.
  4. make
  5. make install The binary will be at [gcc-src]/bin/
like image 3
user2368173 Avatar answered Oct 22 '22 21:10

user2368173


Looks like your make clean didn't actually remove libbackend.a from the build directory; you were still trying to link with the old version of your code compiled against MacPorts. Manually running rm libbackend.a (or make distclean or make spotless or whatever is supposed to really clean everything up) probably fixed the problem, right?

like image 2
Quuxplusone Avatar answered Oct 22 '22 21:10

Quuxplusone