rust 错误:链接'cc'失败:出口代码:1用于货物运行

j2cgzkjk  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(162)

我尝试在M1 Mac上运行cargo run一个简单的hello world应用程序,但遇到以下错误:

Error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-arch" "x86_64" "-L" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.0.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.1.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.10.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.11.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.12.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.13.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.14.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.15.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.2.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.3.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.4.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.5.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.6.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.7.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.8.rcgu.o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.build_script_build.d32uozjy-cgu.9.rcgu.o" "-o" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/build/libc-9d36948631c986a4/build_script_build-9d36948631c986a4.52gec2a5zk7hme9a.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/hugosum/Desktop/portfolio-2021/backend/target/debug/deps" "-L" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libstd-351eea491abe4434.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-5aaa4a9e35148ca2.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libobject-3c363f1c75138766.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-80cce18fbd9a62fa.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libgimli-b559ce52f8e8c310.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-bacdd33101496d8b.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-50c1e0544758a9b9.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-400cf8ef953fa406.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libunwind-d523776aee41e7a3.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-0d288267983a5503.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/liblibc-5768a81ce4924201.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/liballoc-f050e0eba5670fa0.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-618d97e25269c450.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libcore-f02aead32a1ff31d.rlib" "/nix/store/i693mglb2d92m1ycmq5vcsn02xgpra9d-rustc-1.52.1/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-07b5b6ec8d6718bf.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-undefined" "dynamic_lookup"
  = note: ld: library not found for -liconv
          clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

error: aborting due to previous error
error: could not compile `futures-channel`
error: build failed

我已经通过nix安装了cargorustc,并且我已经尝试检查cc bin

❯ cc -v
clang version 7.1.0 (tags/RELEASE_710/final)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /nix/store/rjy3p4j55ac4vyrmg18w2wrjgpfhsh4r-clang-7.1.0/bin

如何修复此错误?

o2g1uqev

o2g1uqev1#

这仍然是第一个谷歌搜索结果为“iconv货物nix”,所以我将张贴我发现的解决方案在这里。
我不确定这是有意的还是nixpkgs中的一个bug,但是这个错误弹出是因为libiconv默认不包含在nix链接器标志中(你可以在$NIX_LDFLAGS中检查)。要包含它,显式安装它,例如通过nix-shell


# ↓↓↓↓↓↓↓↓

nix-shell -p libiconv -p cargo -p rustc -p rust-analyzer -p rustfmt -p clippy

相关问题