Linux x86 编译 Android 遭遇 gnu/stubs-64.h

这两天心血来潮,执行完 repo sync 后,顺手来了一下 make,不料却发现了以下的错误:

host C: libclearsilver-jni <= external/clearsilver/java-jni/j_neo_util.c
In file included from /usr/include/features.h:378,
                      from /usr/include/string.h:26,
		      from external/clearsilver/java-jni/j_neo_util.c:1:
/usr/include/gnu/stubs.h:9:27: error: gnu/stubs-64.h: No such file or directory
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/j_neo_util.o] Error 1

兵来将挡,水来土掩,用关键字 android “error: gnu/stubs-64.h: no such file or directory” 来搜一下吧,发现搜索结果寥寥无几,看样子问题比较新,其中有一个 CSDN 的链接,就顺手点了过去。帖子反映的问题和我一模一样,不过它的分析给了我一些提醒。

从错误信息入手,追踪到/usr/include/gnu/stubs.h,看到如下代码:

#if __WORDSIZE == 32
# include <gnu/stubs-32.h>
#elif __WORDSIZE == 64
# include <gnu/stubs-64.h>
#else
# error "unexpected value for __WORDSIZE macro"
#endif

顺着 WORDSIZE,进入/usr/include/bits/wordsize,发现:

#if defined __x86_64__
# define __WORDSIZE	64
# define __WORDSIZE_COMPAT32	1
#else
# define __WORDSIZE	32
#endif

结合报错的信息,可以知道这里一定是有定义__x86_64__,执行一下 uname -a 可以确认 OS 明明是x86,为什么会__x86_64__呢?追根溯源, Android 源码或许能露出蛛丝马迹。

果不其然,从 android.git.kernel.org 的 platform/external/clearsilver.git 上,看到5天前,有个 Ying Wang 的家伙提交一个修改:Fix 64-bit clearsilver shared library issue,参看这里,修改内容中 java-jni/Android.mk,和出现本次问题的路径 java-jni/j_neo_util.c,同属一个父目录,看样子有点关系,查看 Android.mk 的修改内容,发现做了如下修改:

+# This forces a 64-bit build for Java6
+ifneq ($(filter 1.6%,$(java_version)),)
+    LOCAL_CFLAGS += -m64
+    LOCAL_LDFLAGS += -m64
+endif

当发现你使用Java6时,它将强制使用64-bit,我想这就能解释__x86_64__出现的原因。那么既然它要64-bit,我就满足它。首先要解决 gnu/stubs-64.h: No such file or directory,解决这个问题需要执行以下命令:

[xuhj@eniac mydroid]$ apt-get install libc6-dev-amd64

完成以后再执行 make,发现有错误:

/usr/bin/ld: cannot find -lstdc++

那就继续满足它:

[xuhj@eniac mydroid]$ apt-get install g++-multilib lib64stdc++6

还是不行,又发生下面的错误:

/usr/bin/ld: cannot find -lz

再来执行命令:

[xuhj@eniac mydroid]$ apt-get install lib64z1-dev

19 Comments

Xu Xuesheng7月 7th, 2010 at 6:03 下午

一样的问题,终于解决了。。

anoy7月 11th, 2010 at 10:37 上午

I don’t think it’s the right way to correct it.
It depends on your system, if use 32 bit, then it should be 32 bit; elsewhere 64 bit.

Xu Haojie7月 11th, 2010 at 10:48 上午

我初次看到“This forces a 64-bit build for Java6”,也觉得无法理解,这种方法供参考吧,毕竟它验证可行。

dewang7月 20th, 2010 at 3:19 下午

照此方法后出现
Could not load ‘clearsilver-jni’
不知是否因为“libclearsilver-jni.so”为64bit,在32bit系统无法加载?
最后把java,javac默认改为1.5通过了编译

Xu Haojie7月 20th, 2010 at 6:58 下午

感谢反馈,验证了一下,所提到的问题确实存在。至于是不是在32bit系统无法加载,我还无法做出判断。

Genser7月 23rd, 2010 at 8:41 下午

那么这样的话编译后的处理需要在64位机上进了咯?32bit咋办呢

Xu Haojie7月 23rd, 2010 at 9:35 下午

并不需要,Linux 32-bit + JDK1.5 32-bit 可以通过。

阿呆8月 2nd, 2010 at 4:43 下午

我也遇见这问题了,但在安装 libc6-dev-amd64 时出现问题:
下列的软件包有不能满足的依赖关系:
libc6-dev-amd64: 依赖: libc6-amd64 (= 2.9-4ubuntu6) 但是它将不会被安装
依赖: libc6-dev (= 2.9-4ubuntu6) 但是 2.9-4ubuntu6.1 正要被安装
推荐: gcc-multilib 但是它将不会被安装
E: 无法安装的软件包

Xu Haojie8月 4th, 2010 at 9:58 下午

抱歉,我所运行的 OS 是 Debian,虽然和 Ubuntu 有些渊源,但毕竟是不同的发行版,对包之间的依赖关系不能完全套用,无法对你的问题做出解释。

embeddedman8月 15th, 2010 at 9:43 上午

我在ubuntu8.10下用JDK1.5+32bit编译不行,编译到3个小时左右的时候突然出现如下错误:
/tmp/dftables-Vsb7kj24.in: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Use of uninitialized value $pcre_internal{“tables_length”} in printf at external/webkit/JavaScriptCore/pcre/dftables line 83.
Use of uninitialized value $pcre_internal{“lcc_offset”} in numeric ne (!=) at external/webkit/JavaScriptCore/pcre/dftables line 90.
Use of uninitialized value $pcre_internal{“fcc_offset”} in numeric ne (!=) at external/webkit/JavaScriptCore/pcre/dftables line 108.
fcc_offset != 128 at external/webkit/JavaScriptCore/pcre/dftables line 109.
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libjs_intermediates/chartables.c] Error 25
make: *** Deleting file `out/target/product/generic/obj/STATIC_LIBRARIES/libjs_intermediates/chartables.c’
我在网上找了一天都没发现解决办法,貌似还是得用JDK1.6

ziv cheung10月 10th, 2010 at 5:44 下午

请问:
====================================
照此方法后出现
Could not load ‘clearsilver-jni’
不知是否因为“libclearsilver-jni.so”为64bit,在32bit系统无法加载?
最后把java,javac默认改为1.5通过了编译
====================================
请问怎么把java,javac默认改为1.5,在编译之前的时候,把path设置成1。5的bin吗?

ziv cheung10月 10th, 2010 at 5:53 下午

把path设置成1。5的bin
然后编译 make还是Could not load ‘clearsilver-jni’
请问大侠!

Xu Haojie10月 10th, 2010 at 6:10 下午

建议你通过javac -version来检查变量是否真的生效,正常情况下是可以通过的,希望能帮到你。

silencer11月 26th, 2010 at 10:08 上午

cannot find -lncurses
解决方法:sudo apt-get install lib32ncurses5-dev
还有个会经常出现的错误,希望对大家有用

[…] 原文链接:http://www.poemcode.net/2010/07/android-stubs-64/ >>> 进入[Android2D游戏开发]主题文章列表 转载编辑: Fgamers 转载地址:http://disanji.net/2011/04/02/linux-x86-compile-android-gnustubs-64-h/ 分享到 | blog comments powered by Disqus /* […]

Daisy6月 29th, 2011 at 1:47 下午

apt-get install libc6-dev-amd64
时出现“E: Unable to locate package libc6-dev-amd64″,请问如何解决,感谢!!!

Xu Haojie6月 29th, 2011 at 2:10 下午

从错误信息来看,直接原因是找不到要安装的包,我猜测这或许因为发行版升级或APT源变动。

戴文源6月 6th, 2012 at 5:26 下午

谢谢大侠。
有你这个贴,让我不用装64位系统了!

BTW, 如何才能判断出需要libc6-dev-amd64?

[…] “error: gnu/stubs-64.h: no such file or directory 产生原因仍然是要64位系统 另个牛人的方法 继续编译, 这次/out/target/product又编不过去了。 […]

Leave a comment

Your comment