Welcome 微信登录

首页 / 操作系统 / Linux / 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.cIn 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 directorymake: *** [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,看到如下代码:
  1. <SPAN style="COLOR: #339933">#if __WORDSIZE == 32</SPAN>   
  2. <SPAN style="COLOR: #339933"># include <gnu/stubs-32.h></SPAN>   
  3. <SPAN style="COLOR: #339933">#elif __WORDSIZE == 64</SPAN>   
  4. <SPAN style="COLOR: #339933"># include <gnu/stubs-64.h></SPAN>   
  5. <SPAN style="COLOR: #339933">#else</SPAN>   
  6. <SPAN style="COLOR: #339933"># error "unexpected value for __WORDSIZE macro"</SPAN>   
  7. <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,发现:
  1. <SPAN style="COLOR: #339933">#if defined __x86_64__</SPAN>   
  2. <SPAN style="COLOR: #339933"># define __WORDSIZE    64</SPAN>   
  3. <SPAN style="COLOR: #339933"># define __WORDSIZE_COMPAT32   1</SPAN>   
  4. <SPAN style="COLOR: #339933">#else</SPAN>   
  5. <SPAN style="COLOR: #339933"># define __WORDSIZE    32</SPAN>   
  6. <SPAN style="COLOR: #339933">#endif</SPAN>  
#if defined __x86_64__# define __WORDSIZE64# define __WORDSIZE_COMPAT321#else# define __WORDSIZE32#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,解决这个问题需要执行以下命令:[www.linuxidc.com@linuxidc]$ apt-get install libc6-dev-amd64完成以后再执行 make,发现有错误:/usr/bin/ld: cannot find -lstdc++那就继续满足它:[www.linuxidc.com@linuxidc]$ apt-get install g++-multilib lib64stdc++6还是不行,又发生下面的错误:/usr/bin/ld: cannot find -lz再来执行命令:[www.linuxidc.com@linuxidc]$ apt-get install lib64z1-dev