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

tof*_*tim 4 android icu android-ndk

尝试在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
Run Code Online (Sandbox Code Playgroud)

这由icu/source/common/unicode/ptypes.h中的#include <sys/types.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
Run Code Online (Sandbox Code Playgroud)

这里的结果是uint64_t,它在sys/types.h顶部的#include <stdint.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
Run Code Online (Sandbox Code Playgroud)

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

小智 12

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

对于c ++,那是传递-std=gnu++0x旗帜.对于C来说,这已经过去了-std=c99

即添加类似的行

APP_CPPFLAGS= -std=gnu++0x
Run Code Online (Sandbox Code Playgroud)

到您的Application.mk文件.

或者,您可以通过#define来破解它; 我只是不会分发具有这种黑客的代码,因为它很脆弱.