编译ICU for Android - 'uint64_t'没有命名类型

时间:2012-02-12 07:20:12

标签: android android-ndk icu

尝试在Linux中使用android-ndk-r7交叉编译ICU时,在运行'make'时配置后会出现以下错误

__/android-ndk-r7/platforms/android-8/arch-arm/usr/include/sys/types.h:124: error: 'uint64_t' does not name a type

这是由#include< sys / types.h>触发的。在icu / source / common / unicode / ptypes.h中:25。它似乎是android-ndk-n7中的一个非icu问题。在sys / types.h中我们看到

#ifdef __BSD_VISIBLE
typedef unsigned char   u_char;
typedef unsigned short  u_short;
typedef unsigned int    u_int;
typedef unsigned long   u_long;

typedef uint32_t       u_int32_t;
typedef uint16_t       u_int16_t;
typedef uint8_t        u_int8_t;
typedef uint64_t       u_int64_t;
#endif

这里的culprint是uint64_t,它在#include< stdint.h>中定义。在sys / types.h的顶部。我们在这里看到

#if !defined __STRICT_ANSI__ || __STDC_VERSION__ >= 199901L
#  define __STDC_INT64__
#endif

...

#if defined(__STDC_INT64__)
typedef __int64_t     int64_t;
typedef __uint64_t    uint64_t;
#endif

如果 STRICT_ANSI STDC_VERSION ,因此 STDC_INT64 永远不会被定义,包括sys / types.h会抛出错误,因为永远不会定义uint64_t 。以后调用int64_t(在icu代码中发生)和uint64_t的任何代码也会抛出相同的错误。我的临时解决方法是在#include< sys / types.h>之前在icu的ptypes.h顶部定义 STDC_INT64 。这是个坏主意吗?

5 个答案:

答案 0 :(得分:12)

主要问题是uint64_t不是C99之前的C版本中的已定义类型。 定义它的最佳方法是告诉gcc你想使用哪个标准。

对于c ++,那是传递-std=gnu++0x标志。对于C,那是通过-std=c99

即。添加类似

的行
APP_CPPFLAGS= -std=gnu++0x

到您的Application.mk文件。

或者,您可以通过#define来破解它;我只是不会因为它很脆弱而分发代码。

答案 1 :(得分:3)

-D__STDC_INT64__允许在Android的stdint.h中定义uint64_t和int64_t。

但是,这不是理想的修复方法。该错误与Android,stdint和-std = c ++ 0x有关。有关详细信息,请参阅What's the difference in GCC between -std=gnu++0x and -std=c++0x and which one should be used?。如果你遵循思路,另一个(更好的??)修复是修改icu配置脚本,以便它调用gnu ++ 0x而不是c ++ 0x。这可能是正确的做法。

*** 7238,7244 ****
          OLD_CFLAGS="${CFLAGS}"
          OLD_CXXFLAGS="${CXXFLAGS}"
          CFLAGS="${CFLAGS} -std=gnu99 -D_GCC_"
!         CXXFLAGS="${CXXFLAGS} -std=c++0x"
          cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */

--- 7241,7247 ----
          OLD_CFLAGS="${CFLAGS}"
          OLD_CXXFLAGS="${CXXFLAGS}"
          CFLAGS="${CFLAGS} -std=gnu99 -D_GCC_"
!         CXXFLAGS="${CXXFLAGS} -std=gnu++0x"
          cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  /* end confdefs.h.  */

***************

答案 2 :(得分:1)

我通过在icudefs.mk中加入CPPFLGAS选项-D__STDC_INT64 __

解决了这种情况

答案 3 :(得分:0)

可以设置-DU_HAVE_UINT64_T=0吗?

答案 4 :(得分:0)

更新到NDK 8e它支持更多来自C ++ 11的东西

你的Application.mk也应该包含一些标志来查看我的文件

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1 -std=c++11 -DDEBUG=1
APP_USE_CPP0X := true
NDK_TOOLCHAIN_VERSION=4.7