Linux x86 编译 Android 遭遇 gnu/stubs-64.h
编译Android源码时,gcc将中定义了__x86_64__,编译不过,错误如下。我的PC是32位的,应该如何设置?
这两天心血来潮,执行完 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” 来搜一下吧,发现搜索结果寥寥无几,看样子问题比较新,其中有一个链接,就顺手点了过去。帖子反映的问题和我一模一样,不过它的分析给了我一些提醒。
从错误信息入手,追踪到/usr/include/gnu/stubs.h,看到如下代码:
- <SPAN style="COLOR: #339933">#if __WORDSIZE == 32</SPAN>
- <SPAN style="COLOR: #339933"># include <gnu/stubs-32.h></SPAN>
- <SPAN style="COLOR: #339933">#elif __WORDSIZE == 64</SPAN>
- <SPAN style="COLOR: #339933"># include <gnu/stubs-64.h></SPAN>
- <SPAN style="COLOR: #339933">#else</SPAN>
- <SPAN style="COLOR: #339933"># error "unexpected value for __WORDSIZE macro"</SPAN>
- <SPAN style="COLOR: #339933">#endif</SPAN>
#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,发现:
- <SPAN style="COLOR: #339933">#if defined __x86_64__</SPAN>
- <SPAN style="COLOR: #339933"># define __WORDSIZE 64</SPAN>
- <SPAN style="COLOR: #339933"># define __WORDSIZE_COMPAT32 1</SPAN>
- <SPAN style="COLOR: #339933">#else</SPAN>
- <SPAN style="COLOR: #339933"># define __WORDSIZE 32</SPAN>
- <SPAN style="COLOR: #339933">#endif</SPAN>
#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,解决这个问题需要执行以下命令:
/usr/bin/ld: cannot find -lstdc++
那就继续满足它:
/usr/bin/ld: cannot find -lz
再来执行命令:
[www.linuxidc.com@linuxidc]$ apt-get install lib64z1-dev