LCM/C++ works on Android

800 views
Skip to first unread message

Vilas Chitrakaran

unread,
Aug 22, 2013, 6:05:24 AM8/22/13
to lcm-...@googlegroups.com
Hi all,

Today I finally succeeded in compiling LCM C++ library for android using the Android NDK and tested it on my android devices. The biggest pain in the arse was ofcourse getting glib compiled, but after countless hours of messing around, I have found a process that works. For the benefit of others who may be dealing with the same problem, here's how glib build is done. My build platform is linux (ubuntu 13.04). Once you get through this, compiling LCM is straightforward. I was able to develop a basic Qt app that publishes LCM messages from my phone and have it received on another device.

Glib is required to compile LCM for android. You need android-ndk-r9 to make this work


export NDK_ROOT=$HOME/Programs/android/android-ndk-r9

export API_LEVEL=18

export PREBUILT=$NDK_ROOT/toolchains/arm-linux-androideabi-4.8

export PLATFORM=$NDK_ROOT/platforms/android-$API_LEVEL/arch-arm

export PATH=$PATH:$PREBUILT/prebuilt/linux-x86_64/bin

#export CFLAGS="-fPIC -DANDROID -nostdlib -Wno-multichar"

export CFLAGS="-fPIC -DANDROID -Wno-multichar -I$HOME/Programs/android/include -I$HOME/Programs/android/lib/libffi-3.0.13/include"

export CPPFLAGS="-I$NDK_ROOT/platforms/android-$API_LEVEL/arch-arm/usr/include/ -I$HOME/Programs/android/include -I$HOME/Programs/android/lib/libffi-3.0.13/include -DANDROID -DNO_XMALLOC -mandroid"

export LIBS="-lc "

export LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-$API_LEVEL/arch-arm/usr/lib/ -L$HOME/Programs/android/lib -L$NDK_ROOT/platforms/android-$API_LEVEL/arch-arm/usr/lib"


export CROSS_COMPILE=arm-linux-androideabi

export CC="${CROSS_COMPILE}-gcc --sysroot=$PLATFORM"

export CXX="${CROSS_COMPILE}-g++ --sysroot=$PLATFORM"

export AR=${CROSS_COMPILE}-ar

export AS=${CROSS_COMPILE}-as

export LD=${CROSS_COMPILE}-ld

export RANLIB=${CROSS_COMPILE}-ranlib

export NM=${CROSS_COMPILE}-nm

export STRIP=${CROSS_COMPILE}-strip


  • Compile libiconv

    • tar zxvf libiconv-1.14.tar.gz

    • cd libiconv-1.14

    • ./configure --build=x86_64-unknown-linux-gnu --host=arm-eabi --disable-rpath --prefix=$HOME/Programs/android

    • make

    • make install

    • This will put libiconv.a and other stuff in ~/Programs/android/

  • Compile libffi

    • tar zxvf libffi-3.0.13.tar.gz

    • cd libffi-3.0.13

    • ./configure --build=x86_64-unknown-linux-gnu --host=arm-eabi --prefix=$HOME/Programs/android --enable-static

    • make

    • make install

  • Compile gettext

    • tar zxvf ../gettext-0.18.3.tar.gz .

    • cd gettext-0.18.3

    • ./configure --build=x86_64-unknown-linux-gnu --host=arm-eabi --disable-rpath --prefix=$HOME/Programs/android --disable-libasprintf --disable-java --disable-native-java --disable-openmp --disable-curses

    • make

    • make install

    • This will again install stuff into ~/Programs/android


glib_cv_long_long_format=ll

glib_cv_stack_grows=no

glib_cv_sane_realloc=yes

glib_cv_have_strlcpy=no

glib_cv_va_val_copy=yes

glib_cv_rtldglobal_broken=no

glib_cv_uscore=no

glib_cv_monotonic_clock=no

ac_cv_func_nonposix_getpwuid_r=no

ac_cv_func_posix_getpwuid_r=no

ac_cv_func_posix_getgrgid_r=no

glib_cv_use_pid_surrogate=yes

ac_cv_func_printf_unix98=no

ac_cv_func_vsnprintf_c99=yes

ac_cv_func_realloc_0_nonnull=yes

ac_cv_func_realloc_works=yes


  • ./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-androideabi --prefix=$HOME/Programs/android --disable-dependency-tracking --cache-file=arm.cache --enable-included-printf --enable-static

  • make

  • (fix compile errors as they occur. I got the following three:)

    • gio/gdbusmessage.c, line 3474/3475, change “udi=%d” to “uid=%ld” in g_string_append_printf

    • In gio/gdbusprivate.c, line 2164, typecast second parameter as (unsigned int)bytes_written

    • In gio/gdbusprivate.c, line 2215, typecast second parameter as (unsigned int)bytes_read

  • make install



    To compile LCM now, follow a similar configure/make/make install procedure


    Cheers

    Vilas


Albert Huang

unread,
Aug 22, 2013, 10:48:29 PM8/22/13
to lcm-...@googlegroups.com
Hi Vilas,

Thanks for the detailed report - it definitely looks like getting GLib to compile was quite a pain =/

Albert


--
You received this message because you are subscribed to the Google Groups "Lightweight Communications and Marshalling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lcm-users+...@googlegroups.com.
To post to this group, send email to lcm-...@googlegroups.com.
Visit this group at http://groups.google.com/group/lcm-users.
For more options, visit https://groups.google.com/groups/opt_out.

Himanshu Srivastava

unread,
Sep 7, 2015, 6:04:42 AM9/7/15
to Lightweight Communications and Marshalling
Hi ,

I followed the steps you mentioned in this post for cross compilation.
On running configure command for libiconv it is working fine but on logs , I can see the below statements:


 checking for arm-eabi-dumpbin... no
 checking for arm-eabi-link... no
 checking for arm-eabi-gcc ...no

I am not sure if it is picking the right tool chain.I am running the below command:


./configure --build=x86_64-unknown-linux-gnu --host=arm-eabi --disable-rpath --prefix=$HOME/Programs/android


Reply all
Reply to author
Forward
0 new messages