Using gnu's libiconv for android ndk

1,722 views
Skip to first unread message

Post

unread,
Apr 4, 2012, 3:03:09 AM4/4/12
to android-ndk
Hi, I have just started using android ndk recently and was able to
build and compile some c++ files before. Now, on another project, I
have a problem with this error: "undefined reference to libiconv_open,
libiconv, libiconv_close". I'm really confused on how to use libiconv
for android-ndk, as in I have no idea how to start. I tried searching
the web but there is no tutorial on how to do it for starters, so I
tried downloading libiconv1.13.1 and placing it in my project's jni
folder and tried to build it but an error occurred:

$ /cygdrive/c/android-ndk-r7b/ndk-build -B
Cygwin : Generating dependency file converter script
Compile thumb : iconv <= iconv.c
jni/libiconv-1.13.1/lib/iconv.c:21:19: error: iconv.h: No such file or
directory
jni/libiconv-1.13.1/lib/iconv.c:25:20: error: config.h: No such file
or directory
jni/libiconv-1.13.1/lib/iconv.c:26:26: error: localcharset.h: No such
file or directory
...

I checked in the libiconv folder and found iconv.h.in, I tried to
rename the file to iconv.h but another error occurred:

jni/libiconv-1.13.1/include/iconv.h:25: error: stray '@' in program
jni/libiconv-1.13.1/include/iconv.h:25: error: stray '@' in program
jni/libiconv-1.13.1/include/iconv.h:25: error: expected '=', ',', ';',
'asm' or '__attribute__' before 'int'
In file included from jni/libiconv-1.13.1/lib/iconv.c:21:
jni/libiconv-1.13.1/include/iconv.h:83: error: stray '@' in program
jni/libiconv-1.13.1/include/iconv.h:83: error: expected declaration
specifiers or '...' before 'ICONV_CONST'
jni/libiconv-1.13.1/include/iconv.h:83: error: stray '@' in program
...

I've been googling for some help for 3 days and still found nothing.

Do I have to do something after downloading libiconv before trying to
use it in my ndk project? like installing? or configuring something?

Please tell me what to do, step by step if its ok. Thanks.

Tor Lillqvist

unread,
Apr 5, 2012, 2:17:53 AM4/5/12
to andro...@googlegroups.com
There is so much you are missing it's hard to know where to start...

Yes, you need to "./configure" libiconv before you can compile it, and then "make" and "make install" it. You will need to pass a suitable --host option to the configure script, and set the CC environment variable, to get it to configure for a cross-compilation to Android. Good luck. How well equipped libiconv is for cross-compilation I don't know. You also want to use a --prefix option so that you don't mix up this cross-compiled libiconv with something for your build platform, in /usr/local (which is the default prefix for configure scripts). You must then figure out how to reference the headers and library of this installed cross-compiled libiconv in your project.

Just renaming the iconv.h.in file to iconv.h is not possible. If you would have bothered to have a look inside the .h.in file you would have noticed those @FOO@ things. They are expanded to values determined by the configure script. This is the very point of .in files. This is nothing particular to libiconv, but extremely common in any software that uses GNU autotools. Still, one wonders *what* you were googling for, for 3 days, if you really found *nothing* ?

If you had spent the three days learning how to build Open Source software that uses GNU autotool style build mechanisms, and getting a rough understanding of how the mechanisms work, instead of random googling, you might have learned something. Just learn how the build mechanism works for non-cross-compilations first. Even on Cygwin it should work fairly reliably, but it would be best to use some common Unix system of course, like some common Linux distro, or Mac OS X.

Finally, you need to familiarize yourself with the GNU libiconv license. In case you are building an Android app you intend to distribute to others (whether for free, or for money, makes no difference), you *must* adher to the GNU libiconv license. (Note that there is a group of professionals who have the expertise to give legal advice, they are called lawyers.)

--tml

某因幡

unread,
Apr 5, 2012, 2:28:12 AM4/5/12
to andro...@googlegroups.com
Hello,
If you just need iconv/iconv_open/iconv_close, you can just write a
wrapper over ICU.
It only costs you several KBs of the final binary.


2012/4/5 Tor Lillqvist <t...@iki.fi>:

> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-ndk/-/9294089ZpFAJ.
>
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.

--
language: Chinese, Japanese, English

Tor Lillqvist

unread,
Apr 5, 2012, 2:32:35 AM4/5/12
to andro...@googlegroups.com

If you just need iconv/iconv_open/iconv_close, you can just write a
wrapper over ICU.

Except that Android, even if it uses at least parts of ICU internally, doesn't expose the ICU API, so you certainly should not write code against it. He/she would need to write iconv-style wrappers over the corresponding Java API. (Which would not be hard either, of course.)

--tml

Reply all
Reply to author
Forward
0 new messages