在OSX上交叉编译MIPS MT7688 OpenWRT(mipsel-unknown-linux-musl)

时间:2019-02-11 09:35:15

标签: macos rust mips cross-compiling openwrt

当我尝试每晚使用rustc 1.32.0在OSX上交叉编译Little-endian MIPS的Cargo starter main.rs文件(运行OpenWRT的MT7688处理器)时,出现以下错误:

cargo build --target=mipsel-unknown-linux-musl
   Compiling led v0.1.0 (/Users/petrus/Projects/led)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.2kthj4han7xcr84g.rcgu.o" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.440j3fk0cam0b0pu.rcgu.o" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.482rers61msj2848.rcgu.o" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.498udk2wtgjsw4ib.rcgu.o" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.4uh6jdaux45o6bh1.rcgu.o" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.5fq5qqfqkwjepod2.rcgu.o" "-o" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps/led-fb2a88ec64854daf.49n6u1xnbbs66t12.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/Users/petrus/Projects/led/target/mipsel-unknown-linux-musl/debug/deps" "-L" "/Users/petrus/Projects/led/target/debug/deps" "-L" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-27a0dffe96f2ad3e.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libpanic_unwind-fe8b80af161a561e.rlib" "/var/folders/rl/b7dvjss14wj6415t0v4f7z3m0000gn/T/rustcFd840X/libunwind-ecc019d8c6cb3f8a.rlib" "/var/folders/rl/b7dvjss14wj6415t0v4f7z3m0000gn/T/rustcFd840X/liblibc-5d68beb2e4661bda.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/liballoc-de565f8c0b8e0971.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_core-0a55bee6cc97e346.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libcore-4075eb2b0854a330.rlib" "-Wl,--end-group" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libcompiler_builtins-ecf284221505c8a3.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc"
  = note: clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
          ld: unknown option: --as-needed
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

运行RUSTFLAGS="-C linker=lld"时抛出:

RUSTFLAGS="-C linker=lld" cargo build --target=mipsel-unknown-linux-musl
   Compiling led v0.1.0 (/Users/petrus/Projects/led)
error: linker `lld` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: Could not compile `led`.

To learn more, run the command again with --verbose.

还尝试了RUSTFLAGS="-C linker=rust-lld",它会抛出:

rust-lld: error: unable to find library -lgcc_s
rust-lld: error: unable to find library -lc

据我了解,我需要指定一个链接器工具链,我不知道该如何购买。我也尝试使用xargo和cross and dockcross / linux-mipsel进行编译,但是没有运气。

我会在设备本身上构建它,但是rustup不会在MT7688上安装Rust。如何获取并指定正确的MIPS(小端)链接器工具链?

更新:我发现了一个pre-compiled MIPS GCC for macOS,它抛出`mipsel-elf / bin / ld:无法识别的选项'-Wl,-按需'或“添加符号时出错:错误值”,当我尝试将mipsel-elf-gcc指定为链接器时:

rustc --target=mipsel-unknown-linux-musl -C linker=/Users/petrus/Projects/wallfly/respeaker/bin/gcc-mips/bin/mipsel-elf-gcc ./src/main.rs
error: linking with `/Users/petrus/Projects/bin/gcc-mips/bin/mipsel-elf-gcc` failed: exit code: 1
  |
  = note: "/Users/petrus/Projects/bin/gcc-mips/bin/mipsel-elf-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib" "main.main.7rcbfp3g-cgu.0.rcgu.o" "main.main.7rcbfp3g-cgu.1.rcgu.o" "main.main.7rcbfp3g-cgu.2.rcgu.o" "main.main.7rcbfp3g-cgu.3.rcgu.o" "main.main.7rcbfp3g-cgu.4.rcgu.o" "main.main.7rcbfp3g-cgu.5.rcgu.o" "-o" "main" "main.4s37gsrti678ik8u.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-27a0dffe96f2ad3e.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libpanic_unwind-fe8b80af161a561e.rlib" "/var/folders/rl/b7dvjss14wj6415t0v4f7z3m0000gn/T/rustcLDTUyV/libunwind-ecc019d8c6cb3f8a.rlib" "/var/folders/rl/b7dvjss14wj6415t0v4f7z3m0000gn/T/rustcLDTUyV/liblibc-5d68beb2e4661bda.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/liballoc-de565f8c0b8e0971.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_core-0a55bee6cc97e346.rlib" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libcore-4075eb2b0854a330.rlib" "-Wl,--end-group" "/Users/petrus/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/mipsel-unknown-linux-musl/lib/libcompiler_builtins-ecf284221505c8a3.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc"
  = note: /Users/petrus/Projects/bin/gcc-mips/bin/../lib/gcc/mipsel-elf/7.1.0/../../../../mipsel-elf/bin/ld: /Users/petrus/Projects/bin/gcc-mips/bin/../lib/gcc/mipsel-elf/7.1.0/crtbegin.o: relocation R_MIPS_HI16 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
          /Users/petrus/Projects/bin/gcc-mips/bin/../lib/gcc/mipsel-elf/7.1.0/crtbegin.o: error adding symbols: Bad value
          collect2: error: ld returned 1 exit status

也许我指定错了吗?

0 个答案:

没有答案