构建适用于 iOS 的 ICU

Build ICU for iOS

本文关键字:ICU iOS 适用于 构建      更新时间:2023-10-16

我需要iPhone的ICU库。我试图从 souce 构建它,但是,我得到了这个错误:

   clang++   ...  /Users/petr/Development/icu-cross-compile-master/icu-60-2/source/tools/pkgdata/pkgdata.cpp
/Users/petr/Development/icu-cross-compile-master/icu-60-2/source/tools/pkgdata/pkgdata.cpp:544:18: error: call to unavailable function 'system': not available on iOS
    int result = system(cmd);
                 ^~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/usr/include/stdlib.h:195:6: note: candidate function has been explicitly made unavailable
int      system(const char *) __DARWIN_ALIAS_C(system);
sh ${ICU_SOURCE}/configure --host=arm-apple-darwin --with-cross-build=${PREBUILD_DIR} ${PREFIX}

我的PREFIX配置如下:

--enable-extras=yes 
--enable-tools=yes 
--enable-icuio=yes 
--enable-strict=no 
--enable-static 
--enable-shared=no 
--enable-tests=yes 
--disable-renaming 
--enable-samples=no 
--enable-dyload=no
--with-data-packaging=static

还是有其他方法,如何生成libicudata.a?类似的构建脚本适用于Android,Mac和Win。只有iPhone是问题。

问题是 iOS 11 已弃用system()

我认为快速修复您的方法是使用 Xcode 6,而不是 Xcode 9,因此您可以针对 iOS 7 进行编译作为目标,其中 system(( 未被弃用。

或者,如果你真的需要 iOS 完全兼容的解决方案,你需要重写 ICU 源代码以使用 posix 生成功能而不是 system((。查看此答案以获取更多详细信息:如何使用posix_spawn替换已弃用的"系统"以在Objective-C中启动opendiff?

在 iOS 上成功构建 ICU 作为库的另一种解决方案是不使用配置标志 --build-tools=no 的工具进行构建。以下是我用于为各种平台(包括 android 和 ICU(构建的完整配置标志集。

    --enable-static=yes
    --enable-shared=no
    --enable-extras=no
    --enable-strict=no
    --enable-icuio=no
    --enable-layout=no
    --enable-layoutex=no
    --enable-tests=no
    --enable-samples=no
    --enable-tools=no
    --enable-dyload=no
    --with-data-packaging=archive

我刚刚制作了一个makefile,它将下载ICU源代码并为Mac,Catalyst,iOS Simulator和iOS创建一个通用框架。然后,只需将其拖放到您的项目中即可。

https://github.com/dbquarrel/icu4c-xcframework

可能会帮助你(虽然晚了很多年(。

我的用途是在 sqlite for iOS 中启用 ICU 分词器。