我想在
android上移植Trickle(
https://github.com/mariusaeriksen/trickle).
到目前为止我想到的是,我需要使用NDK独立工具链交叉编译此应用程序所依赖的各个库,主要是“libevent”.
从这篇文章中获得了一些帮助 –
http://warpedtimes.wordpress.com/2010/02/03/building-open-source-libraries-with-android-ndk/
我已经设法用以下’build_android.sh’脚本交叉编译libevent:
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"
现在,当我为涓流应用程序执行相同操作时,我在上面的涓流项目目录中运行与上面相同的脚本时出现以下错误 –
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
configure.in中的相应行是 –
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)) 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
我已经尝试过官方的NDK文档,但无法获得太多帮助.
所以我有几个问题: –
>如何解决上述错误?
>如何告诉编译器链接我之前为android交叉编译的共享库(libevent),以便为android生成最终的可执行命令行应用程序.
而且这甚至可以在Android上移植涓流?
如果我能得到一些帮助或至少链接到一些可以帮助我解决这个问题的文章,我会很高兴.
谢谢 :)
解决方法
对于1.,您至少需要调整configure.in来修改“丑陋,丑陋的黑客”(如源代码中所述)部分:
LIBCGUESS=`echo /lib/libc.so.*`
至
LIBCGUESS="/path/to/ndk/platforms/android-${ANDROID_API_LEVEL}/arch-${TARGET_ARCH}/usr/lib/libc.so"
您应该使用与您要支持的最小值相对应的API级别,而不是使用android-19.
此外,如果您想更好地支持更多的Android设备,您应该调整脚本的其余部分,以便它可以轻松地为其他体系结构交叉编译您的lib(现在NDK支持arm,mips,x86).
对于2.,您可以将–with-libevent = / path / to / libevent_library / parameter添加到./configure的调用中.在这种情况下,在/ path / to / libevent_library中,你应该有./lib/libevent.so和./include/event.h