librime icon indicating copy to clipboard operation
librime copied to clipboard

如何在 iOS 上使用 librime?

Open aalenliang opened this issue 4 years ago • 20 comments

问题

在 Release 中下载了最新版本的 rime-1.5.3-osx.zip,解压后拖入 Xcode 的 iOS 工程,编译后报错:

Building for iOS, but the linked library was built for macOS.

image

期望结果

Release 中能有对应 iOS 上可用的 .a 库,直接可拖入 iOS 工程使用

讨论

其实已经搜到了类似需求的 issue,但是没有描述得很详细,也没有得到解答 https://github.com/rime/librime/issues/352 https://github.com/rime/librime/issues/157

iRime 已经将 librime 的代码编译成了静态库,不过这个项目的代码最近更新在三年前。

对 Makefile 一窍不通,在 StackOverflow 上搜到一个可能相关的问答:Cross-compile to static lib (libgcrypt) for use on iOS,其中提到:

Note that it is not possible to build a universal library that will work for both the iOS Simulator and macOS. iOS/Intel and macOS/Intel are not ABI compatible above the C runtime library (Libc). This answer serves to show you how to crosscompile autoconf based projects for iOS targets, and you can easily lipo the resulting static archives together.

是不是将 xcode.mk 中一些选项修改就能得到 iOS 可用的版本呢?

aalenliang avatar Apr 16 '20 03:04 aalenliang

希望你研究过这个问题之后能给出一份解答。

lotem avatar Apr 17 '20 07:04 lotem

I'm working on this. I've built a very simple bridge to call librime from Swift. Can you wait a few days?

alex-the-man avatar Apr 17 '20 09:04 alex-the-man

@lotem 請問 build rime 的時候, 是不是只需要libopencc.a, 而不需要它的 dictionary? 我在cross compile 的時候, lib 和 opencc-dict都target了arm64, build的時候run不了opencc-dict. 謝謝.

alex-the-man avatar Apr 17 '20 22:04 alex-the-man

@lotem 請問 build rime 的時候, 是不是只需要libopencc.a, 而不需要它的 dictionary? 我在cross compile 的時候, lib 和 opencc-dict都target了arm64, build的時候run不了opencc-dict. 謝謝.

是的,build 只需要 libopencc.a。運行時如果用到簡繁轉換,還需要 json 和轉換出來的 ocd 文件。

lotem avatar Apr 20 '20 04:04 lotem

@aalenliang Can you try: https://github.com/alex-the-man/librime/blob/master/README-iOS.md Please clone my fork. I made some changes.

alex-the-man avatar Apr 20 '20 08:04 alex-the-man

@aalenliang Can you try: https://github.com/alex-the-man/librime/blob/master/README-iOS.md Please clone my fork. I made some changes.

好的,我试试。

aalenliang avatar Apr 20 '20 09:04 aalenliang

@alex-the-man 不好意思,回复晚了。

Clone 之后跳过了 iOS compatible Boost C++ libraries 这一段,直接执行 make xcode/ios/thirdparty,报错:

/librime/thirdparty/src/glog/cmake-build/glog/logging.h:107:2: error: Do not know
      how to define a 32-bit integer quantity on your system

完整输出:make-thirdparty-output.txt

然后按照 iOS compatible Boost C++ libraries 的指导操作了一下,不确定是否正确。

在下载了链接 Release 中的 .zip 包之后,首先把解压的文件移动到 librime 中: boost.bitcode/libs/boost/ios/libboost.a -> /librime/thirdparty/lib/libboost.a boost.bitcode/libs/boost/include/boost -> /librime/thirdparty/include/boost

然后 Create symlinks:

$ link ./thirdparty/lib/libboost.a ./thirdparty/lib/libboost_system.a
$ link ./thirdparty/lib/libboost.a ./thirdparty/lib/libboost_regex.a
$ link ./thirdparty/lib/libboost.a ./thirdparty/lib/libboost_filesystem.a

接着执行 make xcode/ios/thirdparty,但仍然报错:

/librime/thirdparty/src/glog/cmake-build/glog/logging.h:107:2: error: Do not know
      how to define a 32-bit integer quantity on your system

完整输出:make-thirdparty-output-2.txt

aalenliang avatar Apr 21 '20 03:04 aalenliang

感覺好像是沒有完整安裝 xcode sdk. 請問你能先不cross compile, build for OS X 嗎?

alex-the-man avatar Apr 21 '20 08:04 alex-the-man

感覺好像是沒有完整安裝 xcode sdk. 請問你能先不cross compile, build for OS X 嗎?

好的,我试试。

aalenliang avatar Apr 21 '20 08:04 aalenliang

如果還是有問題, 可以試試 xcode-select --install. glog build fail 是因爲它找不到方法define 32bit integer. 如果C的header齊全, 就不會出現這問題.

alex-the-man avatar Apr 21 '20 08:04 alex-the-man

如果還是有問題, 可以試試 xcode-select --install. glog build fail 是因爲它找不到方法define 32bit integer. 如果C的header齊全, 就不會出現這問題.

好的。build for mac 也报的相同的错。xcode-select --install 完了 build for mac 也还是这个错。看起来是我这边配置的问题,晚点我先把 build for mac 跑起来再试试 build for iOS 吧。感谢🙏

aalenliang avatar Apr 21 '20 09:04 aalenliang

請問你在xcode能create 一個 objective c program, declare int32_t a; 嗎

alex-the-man avatar Apr 21 '20 19:04 alex-the-man

declare int32_t a

这样是可以编译成功的

//
//  main.cpp
//

#include <iostream>

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    int32_t a;
    return 0;
}

image

aalenliang avatar Apr 22 '20 08:04 aalenliang

請問你compile for OS X 的時候有先把build directory remove嗎 make clean thirdparty/clean

alex-the-man avatar Apr 25 '20 00:04 alex-the-man

如果有人能用我的 change 成功 build for iOS 請告知. 我會 clean up 我的change 試圖send PR.

alex-the-man avatar Apr 25 '20 00:04 alex-the-man

@alex-the-man hi,我和aalenliang一样进行到make xcode/ios/thirdparty这一步,也是同样的报错。执行make clean thirdparty/clean的时候则提示

make clean thirdparty/clean
rm -Rf build build-static debug
make -f thirdparty.mk clean
make[1]: *** No rule to make target `clean'.  Stop.
make: *** [thirdparty/clean] Error 2

jimmyrogue avatar Jun 23 '20 01:06 jimmyrogue

一番折腾 网上找来的设置了一下.bash_profile的path后

export CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

报错就变成了。。当然我觉得好像更差了。。就恢复了回去

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:807:2: error:
      Unsupported architecture
#error Unsupported architecture
 ^

jimmyrogue avatar Jun 23 '20 03:06 jimmyrogue

@aalenliang 请问你编译成功了吗?

jimmyrogue avatar Jun 23 '20 04:06 jimmyrogue

@aalenliang 请问你编译成功了吗?

不好意思,近期比较忙,没有再尝试这个项目。

aalenliang avatar Jun 23 '20 09:06 aalenliang

@aalenliang 好的理解。。谢谢,我如果后续有进度也会在这里告知

jimmyrogue avatar Jun 23 '20 09:06 jimmyrogue

https://github.com/imfuxiao/Hamster

eagleoflqj avatar Aug 06 '23 18:08 eagleoflqj