android ndk 中的 unicode 支持

发布于 2024-09-27 11:49:28 字数 1229 浏览 3 评论 0原文

我有一个大型 C/C++ 库,需要将其用作 Android NDK 项目的一部分。该库需要能够智能地处理 UTF8 字符串(例如,转换为小写/大写)。

该库具有条件编译功能,可以转至操作系统 API 来进行转换,但似乎没有任何适用于 UTF8 的 Android API。 (mbstowcs 等)

此线程表示使用 JNI 方法do it (!),这是一个相当重量级的解决方案。

我正在考虑构建 ICU,但由于它使用 GNU Autotools,我不确定我能做到吗使用 NDK 工具链。 :/

有没有其他人遇到过这个问题并且除了使用 JNI 之外还做了其他的事情?

编辑:我尝试让 ICU 编译在配置步骤失败:

checking wchar.h usability... no
checking wchar.h presence... yes
configure: WARNING: wchar.h: present but cannot be compiled
configure: WARNING: wchar.h:     check for missing prerequisite headers?
configure: WARNING: wchar.h: see the Autoconf documentation
configure: WARNING: wchar.h:     section "Present But Cannot Be Compiled"
configure: WARNING: wchar.h: proceeding with the preprocessor's result
configure: WARNING: wchar.h: in the future, the compiler will take precedence
checking for wchar.h... yes
checking for library containing wcscpy... none required
checking size of wchar_t... 0
configure: error: There is wchar.h but the size of wchar_t is 0

I have a large C/C++ library that I need to use as part of an Android NDK project. This library needs to be able to intelligently process UTF8 strings (for example, conversion to lowercase/uppercase).

The library has conditional compilation to punt to an OS API to do the conversion, but there don't seem to be any Android APIs for UTF8. (mbstowcs, etc)

This thread says to use JNI methods to do it (!), which is a rather heavy-weight solution.

I was thinking about building ICU, but as it uses GNU Autotools I'm not sure I can make it work with the NDK toolchain. :/

Has anyone else confronted this problem and done something other than use JNI?

EDIT: My attempts to get ICU to compile fail at the configure step:

checking wchar.h usability... no
checking wchar.h presence... yes
configure: WARNING: wchar.h: present but cannot be compiled
configure: WARNING: wchar.h:     check for missing prerequisite headers?
configure: WARNING: wchar.h: see the Autoconf documentation
configure: WARNING: wchar.h:     section "Present But Cannot Be Compiled"
configure: WARNING: wchar.h: proceeding with the preprocessor's result
configure: WARNING: wchar.h: in the future, the compiler will take precedence
checking for wchar.h... yes
checking for library containing wcscpy... none required
checking size of wchar_t... 0
configure: error: There is wchar.h but the size of wchar_t is 0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2024-10-04 11:49:29

我们在 NDK 中使用 ICU。按照 ICU 交叉构建说明中的步骤操作就可以了。基本上,您将拥有一个 ICU 本机目录(例如 Windows 或 Linux)、一个 ICU Cygwin(如果使用此类目录)和另一个 ICU Android (ARM) 目录。听起来很疯狂,但它确实有效!

以下是在 Cygwin 下构建的步骤。我正在使用“CrystaX”NDK r4,但它也应该使用开箱即用的 NDK 进行构建。 ICU 版本 4.4,但也适用于以前的版本。

  1. 补丁:

  2. 构建您的ICU 主机版本(例如 Windows)正常。 (我们将其称为 $HOST_ICU)

  3. 构建 Cygwin ICU:

    • 创建 icu-cygwin 目录(我们将其命名为 $ICU_CROSS_BUILD)
    • 从 icu-cygwin 目录运行“$HOST_ICU/source/runConfigureICU Cygwin”
    • 制作
  4. 构建 ICU 的 NDK 版本:< /p>

    • 创建icu-android目录
    • 来自 icu-android 目录:'$HOST_ICU/source/configure' 以及适当的命令行选项。 --with-cross-build=$ICU_CROSS_BUILD 和 --host=arm-eabi 是必需的。
    • 制作

我使用类似的东西来传递(到步骤#4)CPPFLAGS/CXXFLAGS/CFLAGS:

-I$NDK_ROOT/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

对于LDFLAGS:

-lc -Wl,-rpath-link=$NDK_ROOT/build/platforms/android-8/arch-arm/usr/lib/ -L$NDK_ROOT/build/platforms/android-8/arch-arm/usr/lib/

以及额外的配置参数:

--enable-extras=no --enable-strict=no --enable-static --enable-shared=no --enable-tests=no --enable-samples=no --enable-dyload=no --enable-tools=no --host=arm-eabi --with-data-packaging=archive

我已经有一段时间没有手动完成此操作了,它目前都在基于自定义Python的构建中脚本。如果您遇到任何其他麻烦,我可能可以告诉您问题是什么。

祝你好运!

We are using ICU in the NDK. Follow the steps in the ICU cross building instructions and you'll be OK. Basically you'll have a ICU native directory (for example Windows or Linux), a ICU Cygwin (if using such) and yet another for ICU Android (ARM). Sounds crazy, but it works!

Here are the steps for building under Cygwin. I am using the 'CrystaX' NDK r4, but it should build with the out of the box NDK as well. ICU version 4.4, but has worked with previous versions as well.

  1. Patches:

  2. Build your host version of ICU (e.g. Windows) as per normal. (We'll call this $HOST_ICU)

  3. Build Cygwin ICU:

    • Create a icu-cygwin directory (We'll call this $ICU_CROSS_BUILD)
    • From icu-cygwin dir, run '$HOST_ICU/source/runConfigureICU Cygwin'
    • make
  4. Build NDK version of ICU:

    • Create a icu-android directory
    • From icu-android dir: '$HOST_ICU/source/configure' with appropriate command line options. --with-cross-build=$ICU_CROSS_BUILD and --host=arm-eabi is required.
    • make

I use something like this for passed in (to step #4) CPPFLAGS/CXXFLAGS/CFLAGS:

-I$NDK_ROOT/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

And for LDFLAGS:

-lc -Wl,-rpath-link=$NDK_ROOT/build/platforms/android-8/arch-arm/usr/lib/ -L$NDK_ROOT/build/platforms/android-8/arch-arm/usr/lib/

And additional configure params:

--enable-extras=no --enable-strict=no --enable-static --enable-shared=no --enable-tests=no --enable-samples=no --enable-dyload=no --enable-tools=no --host=arm-eabi --with-data-packaging=archive

I haven't done this manually for a while, it's currently all in a custom Python based build script. If you run into any other troubles, I can probably tell you what the issue is.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文