【问题标题】:android GMP cross compilationandroid GMP交叉编译
【发布时间】:2012-04-22 17:31:16
【问题描述】:

我在 debian/amd64 上,我想使用 NDK-7b 为 android 2.2 交叉编译 GMP。我从 [gmplib](hg clone http://gmplib.org:8000/gmp-5.0gmp) 获取源代码。 我将其配置为:

./configure --enable-shared --host=arm-linux-androideabi --prefix=/home/fabien/android/spica/ndk-standalone-8 CFLAGS="-v -march=armv5te -mtune=xscale -msoft-float -Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-allow-shlib-undefined" PKG_CONFIG_PATH="/home/fabien/android/spica/ndk-standalone-8/lib/pkgconfig" LDFLAGS="-Wl,-rpath-link -Wl,/home/fabien/android/spica/ndk-standalone-8/lib -L/home/fabien/android/spica/ndk-standalone-8/lib"

我通过设置修改了文件 config.h:

/* Define to 1 if you have the `obstack_vprintf' function. */
#ifndef ANDROID
#define HAVE_OBSTACK_VPRINTF 1
#endif
/* Define to 1 if you have the `localeconv' function. */
#ifndef ANDROID
#define HAVE_LOCALECONV 1
#endif
/* Define to 1 if you have the `vsnprintf' function and it works properly. */
#ifndef ANDROID
#define HAVE_VSNPRINTF 1
#endif

我在 Makefile 中更新了 SUBDIRS 参数如下:

 SUBDIRS = tests mpn mpz mpq mpf printf scanf cxx mpbsd demos tune

运行 make 时似乎可以编译:

libtool: link: (cd ".libs" && rm -f "libgmp.so" && ln -s "libgmp.so.10.0.5" "libgmp.so")
libtool: link: ( cd ".libs" && rm -f "libgmp.la" && ln -s "../libgmp.la" "libgmp.la" )

但是当我运行“make check”时,链接器似乎丢失了:

/../../../../arm-linux-androideabi/bin/ld: warning: ld-linux.so.3, needed by /home/fabien/android/spica/sources/gmp/.libs/libgmp.so, not found (try using -rpath or -rpath-link)
t-bswap.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
./.libs/libtests.a(misc.o):(.ARM.exidx.text.align_pointer+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
.
.
.
refmpn.c:(.text.refmpn_get_str+0xb8): undefined reference to `__aeabi_uidiv'
refmpn.c:(.text.refmpn_get_str+0x238): undefined reference to `__aeabi_ui2d'
refmpn.c:(.text.refmpn_get_str+0x250): undefined reference to `__aeabi_dmul'
refmpn.c:(.text.refmpn_get_str+0x254): undefined reference to `__aeabi_d2uiz'
./.libs/libtests.a(refmpn.o):(.ARM.exidx.text.refmpn_get_str+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
/home/fabien/android/spica/sources/gmp/.libs/libgmp.so: undefined reference to `abort@GLIBC_2.4'
/home/fabien/android/spica/sources/gmp/.libs/libgmp.so: undefined reference to `puts@GLIBC_2.4'

有什么提示吗?

【问题讨论】:

  • Fabien R,您知道如何进行编译吗?我也在尝试为 Android 编译 GMP,但没有成功。你碰巧记得你的程序是什么吗?
  • @NicoBellic:不。也许你会幸运地使用最新的 NDK。

标签: android android-ndk cross-compiling gmp


【解决方案1】:

此错误是由于链接器创建目标时未包含包含这些辅助函数(这些是 GCC 辅助函数)的文件。要解决此问题,请将 libgcc.a(包含 GCC 帮助程序函数定义)添加到链接器标志中。

至于lib​​gcc.a的位置,假设gcc版本为arm-linux-androideabi-4.4.3,会是 $NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a

这将修复以下错误(这似乎与缺少 GNU libc 有关):

.libs/libgmp.so: undefined reference to `abort@GLIBC_2.4'
.libs/libgmp.so: undefined reference to `puts@GLIBC_2.4'

上述 2 个错误将始终显示为 android 使用 Bionic libc,而不是 GNU libc

注意:此方法将修复所有系统上的类似问题,而不仅仅是 Android。

【讨论】:

  • 我看到了这个post。由于我使用的是NDK独立编译器,我在CFLAGS中添加了“-nostdlib”,“-L/home/fabien/android/spica/ndk-standalone- 8/lib/gcc/arm-linux-androideabi/4.4.3" 到 LDFLAGS 和 LIBS="-lgcc -lm -ldl -lc"。但我得到了这个输出:arm-linux-androideabi/bin/ld: 警告:libm.so.6,需要... gmp/.libs/libgmp.so。链接器找不到 ld-linux.so.3 和 libgcc_s.so.1。此外,我收到了这条消息: ld: warning: cannot find entry symbol _start;默认为 000096cc
  • 起始符号来自以下文件之一(取决于目标是可执行文件还是库):crtbegin_dynamic.o(可执行文件动态链接)、crtbegin_static.o(可执行静态链接)、 crtbegin_so.o(动态库)。将正确对象的路径作为输入的一部分添加到LD,你应该已经解决了_start符号错误
  • 我通过将 -nostdlib 替换为 -nodefaultlibs 解决了有关符号 _start 的错误。但是启动“make check”时链接器似乎仍然丢失。 configure 将其识别为符合 GNU 标准。
  • 好吧,我发现我的错误了。我添加了选项 -std=c99 并删除了所有包含 -Wl 的引用。它适用于以下命令: ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-androideabi --prefix=/home/fabien/android/spica/ndk-standalone-8 CFLAGS="-v -std=c99 -march=armv5te -mtune=xscale -msoft-float -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 - nodefaultlibs -fPIC -shared "
  • @FabienR 您是否成功地使用用于 armeabi-v7a、arm64-v8a、x86 和 x86_64 的共享和静态库进行了可重复的、最好是自动化的构建?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多