studio ndk android c android-ndk shared-libraries porting

ndk - Porting Trickle to android



android ndk location (1)

Para 1., necesitas al menos adaptar configure.in para modificar la parte "feo, feo, hack" (como saciado en los comentarios fuente):

LIBCGUESS=`echo /lib/libc.so.*`

a

LIBCGUESS="/path/to/ndk/platforms/android-${ANDROID_API_LEVEL}/arch-${TARGET_ARCH}/usr/lib/libc.so"

En lugar de usar android-19, debe usar el nivel de API que corresponde al mínimo que desea admitir.

Además, si desea admitir mejor más dispositivos Android, debe adaptar el resto del script para que también pueda compilar de forma cruzada su lib para otras arquitecturas (ahora el NDK es compatible con arm, mips, x86).

Para 2., puede agregar --with-libevent=/path/to/libevent_library/ parameter a la llamada a ./configure . En este caso, dentro de /path/to/libevent_library , debe tener ./lib/libevent.so y ./include/event.h

Estoy tratando de portar Trickle ( https://github.com/mariusaeriksen/trickle ) en android.

Lo que he descubierto hasta ahora es que necesito compilar de forma cruzada las bibliotecas individuales de las que depende esta aplicación, principalmente ''libevent'', usando la cadena de herramientas independiente NDK.

Recibí ayuda de este artículo: http://warpedtimes.wordpress.com/2010/02/03/building-open-source-libraries-with-android-ndk/

Logré compilar de forma cruzada libevent con el siguiente script ''build_android.sh'':

export ANDROID_ROOT=/home/narayan/installations/android-ndk-r9d export PATH=$PATH:$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin export PATH=$PATH:$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/include #Since it complains about crtbegin and crtend ln -s $ANDROID_ROOT/platforms/android-19/arch-arm/usr/lib/crtbegin_so.o ln -s $ANDROID_ROOT/platforms/android-19/arch-arm/usr/lib/crtend_so.o ./configure / --host=arm-linux-androideabi / CC=$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux- androideabi-gcc / LD=$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld / AR=$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar / RANLIB=$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib / CPPFLAGS="-I$ANDROID_ROOT/platforms/android-19/arch-arm/usr/include/" / CFLAGS="-nostdlib" / LDFLAGS="-Wl,-rpath-link=$ANDROID_ROOT/platforms/android-19/arch-arm/usr/lib/ -L$ANDROID_ROOT/platforms/android-19/arch-arm/usr/lib/" / LIBS="-lc -lgcc -L$ANDROID_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.8"

Ahora, cuando hago lo mismo con la aplicación de goteo, obtengo el siguiente error al ejecutar el mismo script que el anterior dentro del directorio de proyectos de goteo:

checking build system type... x86_64-unknown-linux-gnu checking host system type... arm-unknown-linux-androideabi checking target system type... arm-unknown-linux-androideabi checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets $(MAKE)... yes checking for working aclocal-1.4... missing checking for working autoconf... missing checking for working automake-1.4... missing checking for working autoheader... missing checking for working makeinfo... missing checking for arm-linux-androideabi-gcc... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... yes checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc accepts -g... yes checking for /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to accept ANSI C... none needed checking for a sed that does not truncate output... /bin/sed checking for egrep... grep -E checking for ld used by /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld checking if the linker (/home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) is GNU ld... yes checking for /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld option to reload object files... -r checking for BSD-compatible nm... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm -B checking whether ln -s works... yes checking how to recognise dependent libraries... pass_all checking how to run the C preprocessor... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking for arm-linux-androideabi-g++... arm-linux-androideabi-g++ checking whether we are using the GNU C++ compiler... yes checking whether arm-linux-androideabi-g++ accepts -g... yes checking how to run the C++ preprocessor... arm-linux-androideabi-g++ -E checking for arm-linux-androideabi-g77... no checking for arm-linux-androideabi-f77... no checking for arm-linux-androideabi-xlf... no checking for arm-linux-androideabi-frt... no checking for arm-linux-androideabi-pgf77... no checking for arm-linux-androideabi-fort77... no checking for arm-linux-androideabi-fl32... no checking for arm-linux-androideabi-af77... no checking for arm-linux-androideabi-f90... no checking for arm-linux-androideabi-xlf90... no checking for arm-linux-androideabi-pgf90... no checking for arm-linux-androideabi-epcf90... no checking for arm-linux-androideabi-f95... no checking for arm-linux-androideabi-fort... no checking for arm-linux-androideabi-xlf95... no checking for arm-linux-androideabi-ifc... no checking for arm-linux-androideabi-efc... no checking for arm-linux-androideabi-pgf95... no checking for arm-linux-androideabi-lf95... no checking for arm-linux-androideabi-gfortran... no checking for g77... no checking for f77... no checking for xlf... no checking for frt... no checking for pgf77... no checking for fort77... no checking for fl32... no checking for af77... no checking for f90... no checking for xlf90... no checking for pgf90... no checking for epcf90... no checking for f95... no checking for fort... no checking for xlf95... no checking for ifc... no checking for efc... no checking for pgf95... no checking for lf95... no checking for gfortran... no checking whether we are using the GNU Fortran 77 compiler... no checking whether accepts -g... no checking the maximum length of command line arguments... 32768 checking command to parse /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm -B output from /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc object... ok checking for objdir... .libs checking for arm-linux-androideabi-ar... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar checking for arm-linux-androideabi-ranlib... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib checking for arm-linux-androideabi-strip... arm-linux-androideabi-strip checking if /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc static flag works... yes checking if /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -fno-rtti -fno-exceptions... no checking for /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to produce PIC... -fPIC checking if /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc PIC flag -fPIC works... yes checking if /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -c -o file.o... yes checking whether the /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc linker (/home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes configure: creating libtool appending configuration tag "CXX" to libtool checking for ld used by arm-linux-androideabi-g++... /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld checking if the linker (/home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) is GNU ld... yes checking whether the arm-linux-androideabi-g++ linker (/home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) supports shared libraries... yes checking for arm-linux-androideabi-g++ option to produce PIC... -fPIC checking if arm-linux-androideabi-g++ PIC flag -fPIC works... yes checking if arm-linux-androideabi-g++ supports -c -o file.o... yes checking whether the arm-linux-androideabi-g++ linker (/home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) supports shared libraries... yes checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes appending configuration tag "F77" to libtool checking whether make sets $(MAKE)... (cached) yes checking for arm-linux-androideabi-ranlib... (cached) /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib checking for a BSD-compatible install... /usr/bin/install -c checking for socket in -lsocket... no checking for gethostbyname in -lnsl... no checking for dlopen in -ldl... yes checking for err in -lc... yes checking for ANSI C header files... (cached) yes checking for sys/wait.h that is POSIX.1 compatible... yes checking if libc defines __progname... yes checking sys/ioctl.h usability... yes checking sys/ioctl.h presence... yes checking for sys/ioctl.h... yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking err.h usability... yes checking err.h presence... yes checking for err.h... yes checking time.h usability... yes checking time.h presence... yes checking for time.h... yes checking for unistd.h... (cached) yes checking for stdint.h... (cached) yes checking netinet/in.h usability... yes checking netinet/in.h presence... yes checking for netinet/in.h... yes checking asm/poll.h usability... yes checking asm/poll.h presence... yes checking for asm/poll.h... yes checking for an ANSI C-conforming const... yes checking for pid_t... yes checking for size_t... yes checking whether time.h and sys/time.h may both be included... yes checking for u_int64_t... yes checking for u_int32_t... yes checking for u_int16_t... yes checking for u_int8_t... yes checking for in_addr_t... no checking whether /home/narayan/installations/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc needs -traditional... no checking return type of signal handlers... void checking for socket... yes checking for strlcat... yes checking for strlcpy... yes checking for daemon... yes checking for setenv... yes checking for strsep... yes checking for sendfile... yes checking for libevent... yes checking if underscores are needed for symbols... no checking if we can access libc without dlopen... no checking if we can access libc with libc.so... no checking if we can access libc with /usr/lib/libc.so*... no configure: error: Couldn''t figure out how to access libc

Las líneas correspondientes en configure.in son:

AC_MSG_CHECKING(if we can access libc without dlopen) AC_TRY_RUN( #include <dlfcn.h> #include <stdio.h> int main(int argc, char **argv) { void *dh; dh = (void *)-1L; if (dlsym(dh, "printf") != NULL || dlsym(dh, "_printf") != NULL) exit(0); exit(1); }, [AC_MSG_RESULT(yes) AC_DEFINE(NODLOPEN) HAVEMETHOD=yes], AC_MSG_RESULT(no), AC_MSG_RESULT(no)) if test "$HAVEMETHOD" = "no"; then dnl ugly, ugly hack LIBCGUESS=`echo /lib/libc.so.*` USRLIBCGUESS=`echo /usr/lib/libc.so*` if test "$USRLIBCGUESS" = "/usr/lib/libc.so.*"; then USRLIBCGUESS="" fi if test "$LIBCGUESS" = "/lib/libc.so.*"; then LIBCGUESS="" fi for TESTLIB in libc.so `echo $USRLIBCGUESS` `echo $LIBCGUESS` do AC_MSG_CHECKING(if we can access libc with $TESTLIB) AC_TRY_RUN( #include <dlfcn.h> #include <stdio.h> int main(int argc, char **argv) { void *dh; if (dlopen("$TESTLIB", RTLD_LAZY) != NULL) exit(0); exit(1); }, [AC_MSG_RESULT(yes) AC_DEFINE_UNQUOTED(DLOPENLIBC, "$TESTLIB") HAVEMETHOD=yes], AC_MSG_RESULT(no), AC_MSG_RESULT(no)) if test "$HAVEMETHOD" = "yes"; then break fi done fi if test "$HAVEMETHOD" = "no"; then AC_MSG_ERROR(Couldn''t figure out how to access libc) fi

He intentado con la documentación oficial de NDK pero no pude obtener mucha ayuda.

Entonces tengo un par de preguntas:

  1. ¿Cómo resolver el error anterior?
  2. Cómo decirle al compilador que vincule la biblioteca compartida (libevent) que he compilado de forma cruzada para Android antes para generar la aplicación de línea de comandos ejecutable final para Android.

¿Y también es posible exportar goteo en Android?

Estaría encantado si pudiera obtener ayuda o al menos enlaces a algunos artículos que me ayudarían con este problema.

Gracias :)