【问题标题】:ICU library in Android NDKAndroid NDK 中的 ICU 库
【发布时间】:2011-05-09 07:28:34
【问题描述】:

我正在尝试为依赖于 ICU 库(libicuuc.so 和 libicui18n.so)的 C 库创建 JNI 包装器。

我尝试在我的 NDK(标准版本和 CrystaX 版本,在 Mac OS X 机器上)中构建 ICU4C,但一直遇到如下链接问题:

/Users/kyip/KyVmShared/KyAndroid/myproject/obj/local/armeabi/objs/icuuc/udata.o: In function `openCommonData':
/Users/kyip/KyVmShared/KyAndroid/myproject/jni/icu4c/common/udata.c:836: undefined reference to `icudt42_dat'
/Users/kyip/KyVmShared/KyAndroid/myproject/obj/local/armeabi/objs/icuuc/ustr_wcs.o: In function `_strFromWCS':
/Users/kyip/KyVmShared/KyAndroid/myproject/jni/icu4c/common/ustr_wcs.c:365: undefined reference to `wcstombs'
/Users/kyip/KyVmShared/KyAndroid/myproject/jni/icu4c/common/ustr_wcs.c:415: undefined reference to `wcstombs'
/Users/kyip/KyVmShared/KyAndroid/myproject/jni/icu4c/common/ustr_wcs.c:314: undefined reference to `wcstombs'
/Users/kyip/KyVmShared/KyAndroid/myproject/obj/local/armeabi/objs/icuuc/ustr_wcs.o: In function `_strToWCS':
/Users/kyip/KyVmShared/KyAndroid/myproject/jni/icu4c/common/ustr_wcs.c:164: undefined reference to `mbstowcs'
collect2: ld returned 1 exit status

我也尝试了unicode support in android ndk 给出的建议,但没有运气。我被困在:

arm-eabi-g++ -I/ky/crystax/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/include/ -O3 -fno-short-wchar -DU_USING_ICU_NAMESPACE=0 -DU_GNUC_UTF16_STRING=0 -fno-short-enums -nostdlib -fPIC -DU_COMMON_IMPLEMENTATION  -D_REENTRANT -I../common -I../../icu/source/common -I../../icu/source/i18n   "-DDEFAULT_ICU_PLUGINS=\"/usr/local/lib/icu\" "  -DU_COMMON_IMPLEMENTATION -DHAVE_CONFIG_H  -I/ky/crystax/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/include/ -O3 -fno-short-wchar -DU_USING_ICU_NAMESPACE=0 -DU_GNUC_UTF16_STRING=0 -fno-short-enums -nostdlib -fPIC -DU_COMMON_IMPLEMENTATION  -std=c++0x  -fvisibility=hidden -c   -o errorcode.ao ../../icu/source/common/errorcode.cpp
In file included from ../../icu/source/common/unicode/ptypes.h:23,
                 from ../../icu/source/common/unicode/umachine.h:52,
                 from ../../icu/source/common/unicode/utypes.h:36,
                 from ../../icu/source/common/errorcode.cpp:17:
/ky/crystax/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/include/sys/types.h:122: error: 'uint64_t' does not name a type
make[1]: *** [errorcode.ao] Error 1
make: *** [all-recursive] Error 2

任何帮助将不胜感激。

【问题讨论】:

  • 你好..你解决了这个问题吗?我也面临同样的问题。
  • 大声笑,经过从 Cygwin(路径问题)到 Linux(wchar_t 问题)的漫长旅程,我现在到达了 MacOSX - 'uint64_t' 没有命名类型。
  • 奇怪的是配置显示“正在检查 uint64_t...是”,但 types.h:124: error: 'uint64_t' 没有命名类型。我尝试切换到 android-9 无济于事。
  • code.google.com/p/android/issues/detail?id=1952 对此进行了一些讨论——显然“使用 -ansi 构建时,#includes 的任何内容都会出现“uint64_t not defined”编译错误。”

标签: android-ndk icu


【解决方案1】:

这个问题似乎涉及两个文件。 icu/source/common/unicode/ptypes.h 调用 sys/types.h 包括

#if ! U_HAVE_UINT64_T
    typedef unsigned long long uint64_t;
/* else we may not have a 64-bit type */
#endif

通过包含来自 Android 的 sys/types.h,我们涉及(在第 122/124 行附近)

#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

好像uint64_t在赋值给u_int64_t的时候还没有声明。实际上, sys/types.h 包括 stdint.h ,它具有以下内容:

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

typedef __int8_t      int8_t;
typedef __uint8_t     uint8_t;
typedef __int16_t     int16_t;
typedef __uint16_t    uint16_t;
typedef __int32_t     int32_t;
typedef __uint32_t    uint32_t;
#if defined(__STDC_INT64__)
typedef __int64_t     int64_t;
typedef __uint64_t    uint64_t;
#endif

可能没有定义 STRICT_ANSI。似乎这是 sys/types.h 中的 Android 代码中的错误。如果 STDC_INT64 没有定义,它就不会定义 uint64_t,所以它不能定义 u_int64_t。也许真正的解决方案是修改 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;
$if defined(__STDC_INT64__)
typedef uint64_t       u_int64_t;
#endif
#endif

如果你解决了这个问题,下一个错误将在 cstring.h:109 中

icu/source/common/cstring.h:109: error: 'int64_t' has not been declared

如果你改为在 common/unicode/ptypes.h 中 #define STDC_INT64 它将走得更远,但会在

icu/source/common/ustrenum.cpp:118: error: must #include <typeinfo> before using typeid

这里有更多信息:http://groups.google.com/group/android-ndk/browse_thread/thread/2ec9dc289d815ba3?pli=1 但没有真正的解决方案

【讨论】:

  • typeinfo - 您是否尝试在没有 RTTI 的情况下进行编译?在 ustrenum.cpp 的顶部有一个 #include
  • Steven,你曾经在 Android 中编译过 ICU 吗?
  • 我无法这样做。您可以尝试 ICU 49 候选版本,看看是否有更好的结果。
  • 我正在考虑这个问题。 RC 和 49 最终版本之间是否有任何重大变化?
  • 最终版本将在几天后发布,但基本上不会。
【解决方案2】:

我也有这个问题: 未定义对“mbstowcs”的引用

您应该构建和链接更高版本的 android api。

注意: 我试图将它与来自 android-ndk/platforms/android-4 的库链接...我以为 4 是 Android 版本,但 4 是 Android API 版本。而且Android API 4对应Android 1.6 女巫非常非常老了libc中真的没有mbstowcs函数

【讨论】:

    【解决方案3】:

    这是我解决问题的方法。它很脏,但它有效。该库已编译:

    1。文件:/icu4c/common/cwchar.h

    注释掉#if U_HAVE_WCHAR_H 和各自的#endif,所以&lt;wchar.h&gt; 总是包含在内。

    将之前的 uprv_wcstombs 定义替换为:

    #define uprv_wcstombs(mbstr, wcstr, count) U_STANDARD_CPP_NAMESPACE wcs2mbs(mbstr, wcstr, count)
    

    将之前的 uprv_mbstowcs 定义替换为:

    #define uprv_mbstowcs(wcstr, mbstr, count) U_STANDARD_CPP_NAMESPACE mbs2wcs(wcstr, mbstr, count)
    

    2。文件:/icu4c/common/ustr_wcs.cpp

    在顶部某处,在已经存在的包含下添加以下行:

    #include "../wcsmbs.h"
    

    3。创建新文件“icu4c/wcsmbs.h”

    size_t mbs2wcs(wchar_t * __ restrict pwcs, const char * __ restrict s, size_t n)
    {
    
       mbstate_t mbs;
       const char *sp;
       memset(&mbs, 0, sizeof(mbs));
       sp=s;
       return (mbsrtowcs(pwcs,&sp,n,&mbs));
    }
    
    
    size_t wcs2mbs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
    {
       mbstate_t mbs;
       const wchar_t *pwcsp;
       memset(&mbs,0,sizeof(mbs));
       pwcsp = pwcs;
       return (wcsrtombs(s,&pwcsp,n,&mbs));
    }
    

    希望对你有帮助。

    【讨论】:

      【解决方案4】:

      已努力为作为系统一部分的 ICU 库提供 NDK 包装器:https://android-review.googlesource.com/c/153001/

      【讨论】:

        猜你喜欢
        • 2013-08-16
        • 1970-01-01
        • 2018-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-23
        • 2015-03-27
        相关资源
        最近更新 更多