In Apple M1, when I compile my Rust code for Linux X86_64, I get an error ld: unknown option: --as-needed
:
~/WORKDIR/rust/helloworld ⌚ 20:24:21
$ cargo build --target x86_64-unknown-linux-gnu
Compiling helloworld v0.1.0 (/Users/fudenglong/WORKDIR/rust/helloworld)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.19lk9s4zgix5szcj.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.1m3icqtseu62rr0o.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.2fy0lykh93934k3s.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.31qjfvz3m1ka31b5.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.3vrcx702oe0jhs7q.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.53gv3v3m2hy2kzin.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.cc5ryu0ilsy4zts.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.zedrxxva8ppoktz.rcgu.o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10.2l2aexzp1dl763ew.rcgu.o" "-Wl,--as-needed" "-L" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/Users/fudenglong/WORKDIR/rust/helloworld/target/debug/deps" "-L" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-1b64d5fe7a3c3d7f.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e7f86684b9679284.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-10a87791239bd676.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-0e6cad6dd623d38e.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-9d05dd05a4d51b33.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-a60ff138fe1adfad.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-0e9344458c09713e.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-ef3b808d96f639bf.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e3ce420901586b53.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-546bece8dd1bea42.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-9b358af16d7d7aa1.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-554cd499fe1a3b52.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-d105877dbe329cd1.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8fec8a74c706e4b4.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-e869a247063ed69a.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4896c4057dc9553a.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2a6a2797f7a73818.rlib" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0e3656b1fda5fd7b.rlib" "-Wl,--end-group" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1f103368fa522bc0.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/Users/fudenglong/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/Users/fudenglong/WORKDIR/rust/helloworld/target/x86_64-unknown-linux-gnu/debug/deps/helloworld-42c0bc1b0d56de10" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
= 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)
error: could not compile `helloworld` due to previous error
I had already installed the x86_64-unknown-linux-gnu
toolchain.