iOS设备架构交叉编译Rust时缺少标准库组件(Arm7,Armv7)使用Cargo

时间:2016-07-19 02:34:20

标签: ios rust rust-cargo

我正在使用Cargo为iOS架构构建我的Rust库(i386-apple-ios x86_64-apple-ios armv7-apple-ios armv7s-apple-ios aarch64-apple-ios)。我在为Armv7和Armv7s iOS设备架构构建时遇到了问题。关于丢失标准库组件(例如,memcpy,memset等),我遇到了错误。虽然(i386和i686)以及Arm64也适用于模拟器。

我尝试了两种使用Cargo进行交叉编译的方法:

  1. 为所有iOS架构安装Rustup工具链目标。
  2. 使用我的配置设置为所有iOS体系结构的目标来构建Rustc(../configure --target = armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,aarch64-apple-ios, x86_64-apple-ios --prefix = $ HOME / rustc-ios)每https://www.bignerdranch.com/blog/building-an-ios-app-in-rust-part-1/
  3. 当我尝试接近#1时,我收到以下错误:

    架构armv7的未定义符号:

      "memset", referenced from:
          ___aeabi_memset in libtest_sst.a(aeabi_memset.o)
          ___aeabi_memclr in libtest_sst.a(aeabi_memset.o)
         (maybe you meant: ___aeabi_memset)
      "memcpy", referenced from:
          ___aeabi_memcpy in libtest_sst.a(aeabi_memcpy.o)
         (maybe you meant: ___aeabi_memcpy)
      "memcmp", referenced from:
          ___aeabi_memcmp in libtest_sst.a(aeabi_memcmp.o)
         (maybe you meant: ___aeabi_memcmp)
      "___aeabi_dsub", referenced from:
          ___aeabi_drsub in libtest_sst.a(aeabi_drsub.o)
      "___aeabi_fsub", referenced from:
          ___aeabi_frsub in libtest_sst.a(aeabi_frsub.o)
      "__aeabi_fcmplt", referenced from:
          ___aeabi_cfcmple in libtest_sst.a(aeabi_cfcmp.o)
         (maybe you meant: ___aeabi_fcmplt)
      "__aeabi_fcmpeq", referenced from:
          ___aeabi_cfcmple in libtest_sst.a(aeabi_cfcmp.o)
         (maybe you meant: ___aeabi_fcmpeq)
      "__aeabi_cfcmpeq_check_nan", referenced from:
          ___aeabi_cfcmpeq in libtest_sst.a(aeabi_cfcmp.o)
         (maybe you meant: ___aeabi_cfcmpeq_check_nan)
      "memmove", referenced from:
          ___aeabi_memmove in libtest_sst.a(aeabi_memmove.o)
         (maybe you meant: ___aeabi_memmove)
      "__aeabi_dcmpeq", referenced from:
          ___aeabi_cdcmple in libtest_sst.a(aeabi_cdcmp.o)
         (maybe you meant: ___aeabi_dcmpeq)
      "__aeabi_cdcmpeq_check_nan", referenced from:
          ___aeabi_cdcmpeq in libtest_sst.a(aeabi_cdcmp.o)
         (maybe you meant: ___aeabi_cdcmpeq_check_nan)
      "__aeabi_cfcmple", referenced from:
          ___aeabi_cfcmpeq in libtest_sst.a(aeabi_cfcmp.o)
          ___aeabi_cfrcmple in libtest_sst.a(aeabi_cfcmp.o)
         (maybe you meant: ___aeabi_cfcmple)
      "__aeabi_dcmplt", referenced from:
          ___aeabi_cdcmple in libtest_sst.a(aeabi_cdcmp.o)
         (maybe you meant: ___aeabi_dcmplt)
      "__aeabi_cdcmple", referenced from:
          ___aeabi_cdcmpeq in libtest_sst.a(aeabi_cdcmp.o)
          ___aeabi_cdrcmple in libtest_sst.a(aeabi_cdcmp.o)
         (maybe you meant: ___aeabi_cdcmple)
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    当我尝试接近#2时,我收到以下错误:

    架构armv7的未定义符号:

      "___aeabi_fsub", referenced from:
          ___aeabi_frsub in libtest_sst.a(aeabi_frsub.c.o)
      "___aeabi_dsub", referenced from:
          ___aeabi_drsub in libtest_sst.a(aeabi_drsub.c.o)
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    用于生成最终静态库的Makefile如下所示:

    ARCHS = i386-apple-ios x86_64-apple-ios armv7-apple-ios armv7s-apple-ios aarch64-apple-ios
    LIB = libtest.a
    
    all: $(LIB)
    
    .PHONY: $(ARCHS)
    $(ARCHS): %:
            cargo build --verbose --no-default-features --features=no_network --target $@
    
    $(LIB): $(ARCHS)
            lipo -create -output $@ $(foreach arch,$(ARCHS),$(wildcard target/$(arch)/debug/$(LIB)))
    

    我的Cargo.toml看起来像这样:

    [package]
    name = "test"
    version = "0.1.0"
    authors = ["test <test@test.com>"]
    
    build = "build.rs"
    
    [lib]
    name = "test"
    crate-type = ["staticlib"]
    
    [features]
    
    default = ["hyper"]
    no_network = []
    
    [build-dependencies]
    serde_codegen = "*"
    
    [dependencies]
    # error-chain = "*"
    hyper = { version = "*", optional = true }
    libc = "*"
    murmur3 = "*"
    quick-error = "*"
    serde = "*"
    serde_json = "*"
    time = "*"
    url = "*"
    

    我实际上不确定我是否正确安装了工具链。我在另一个问题中发布了这个问题: Unable to override Rustup toolchain for custom build of iOS Toolchain

    这是build.rs代码:

    extern crate serde_codegen;
    
    use std::env;
    use std::path::Path;
    
    fn serde_codegen_data(data_class: &str) {
      let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR expected");
    
      let src_name = format!("src/data/{}.rs.in", data_class);
      let src = Path::new(&src_name);
    
      let dst_name = format!("{}.rs", data_class);
      let dst = Path::new(&out_dir).join(&dst_name);
    
      serde_codegen::expand(&src, &dst).expect("serde_codegen");
    }
    
    pub fn main() {
        serde_codegen_data("audience");
        serde_codegen_data("condition");
        serde_codegen_data("dimension");
        serde_codegen_data("event");
        serde_codegen_data("experiment");
        serde_codegen_data("project");
        serde_codegen_data("traffic_allocation");
        serde_codegen_data("variation");
        serde_codegen_data("group");
    }
    

    此外,在XCode中,我还尝试链接以下库:

    图书馆:系统 框架:基金会 图书馆:objc 框架:安全 图书馆:c 图书馆:m

    根据货物输出警告。但是,我仍然得到同样的错误。

    [Update 7/21/16]

    刚从https://github.com/TimNN/cargo-lipo尝试了Cargo Lipo,但我仍然得到完全相同的错误。

0 个答案:

没有答案