2

ICUライブラリ(libicuuc.soおよびlibicui18n.so)に依存するCライブラリのJNIラッパーを作成しようとしています。

NDK(Mac OS Xマシンの標準バージョンとCrystaXバージョンの両方)で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

また、android ndkのUnicodeサポートで提供された提案を試しましたが、うまくいきませんでした。私は立ち往生しました:

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

どんな助けでもいただければ幸いです。

4

4 に答える 4

0

この問題には 2 つのファイルが関係しているようです。sys/types.h を呼び出す icu/source/common/unicode/ptypes.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

u_int64_tに代入する際にuint64_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 でSTDC_INT64を #defineすると、かなり先に進みますが、

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しかし、実際の解決策はありません

于 2012-02-10T07:09:51.843 に答える
0

私もこの問題を抱えていました:「mbstowcs」への未定義の参照

より高いバージョンの Android API をビルドしてリンクする必要があります。

注: android-ndk/platforms/android-4 のライブラリとリンクしようとしました... 4 は Android のバージョンだと思っていましたが、4 は Android API のバージョンです。Android API 4 は Android 1.6 に対応しています 魔女は非常に古く、libc には実際には mbstowcs 関数がありません

于 2013-05-23T12:19:21.020 に答える
0

これが私が問題を解決した方法です。汚れていますが動作します。ライブラリがコンパイルされました:

1. ファイル: /icu4c/common/cwchar.h

#if U_HAVE_WCHAR_Hと をそれぞれコメントアウトして #endif<wchar.h>が常に含まれるようにします。

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));
}

それが役に立てば幸い。

于 2014-06-24T03:39:48.930 に答える