将涓流移植到安卓
Posted
技术标签:
【中文标题】将涓流移植到安卓【英文标题】:Porting Trickle to android 【发布时间】:2014-07-17 12:58:45 【问题描述】:我正在尝试在 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), 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 上移植涓涓细流吗?
如果我能得到一些帮助,或者至少是一些文章的链接可以帮助我解决这个问题,我会很高兴。
谢谢:)
【问题讨论】:
你好,你编译好涓流交叉了吗?我也遇到了Couldn't figure out how to access libc
,但找不到解决方法。
【参考方案1】:
对于 1.,您至少需要修改 configure.in 以修改“丑陋,丑陋的 hack”(如源 cmets 中所述)部分:
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.,您可以在对 ./configure
的调用中添加 --with-libevent=/path/to/libevent_library/
参数。在这种情况下,在/path/to/libevent_library
中,您应该有./lib/libevent.so
和./include/event.h
【讨论】:
我已经尝试更新 LIBCGUESS 以指向我的 NDK 文件夹中的正确 API,但结果是一样的。如果我错了,请纠正我,但我想我需要运行 autoreconf 才能使对 configure.in 所做的更改生效。此外,我尝试单独运行 configure.in 中的“dlopen()”块(在单独的 c 文件中),以确保它确实检查 libc。测试对安装在系统中的 libc.so.6 为阳性,但对 NDK Android API 19 libc 失败。 我不太了解automake,但我想是的。再次查看源代码,测试是“AC_TRY_RUN”,它将在您的主机上运行已编译的代码。交叉编译时这是行不通的。 sourceware.org/autobook/autobook/autobook_269.html 感谢“--with-libevent”。我在 configure --help 中找到了它:)。关于最低 API,由于涓流使用“LD_PRELOAD”,据我所知,API>14 是必需的。而且android允许我们使用'LD_PRELOAD'的方式和unix有点不同,所以trickle的源代码需要修改。但在此之前,我需要确保我可以为 android-arm-eabi 交叉编译涓流。 确实有帮助。我相信要么我必须大量修改 configure.in,要么必须取消涓流构建系统并编写 Makefile 并使用 ndk-build。谢谢。以上是关于将涓流移植到安卓的主要内容,如果未能解决你的问题,请参考以下文章