gpt4 book ai didi

macos - 错误 : linking with `cc` failed: exit code: 1

转载 作者:行者123 更新时间:2023-11-29 07:54:42 24 4
gpt4 key购买 nike

我有一个单个 .rs 文件。当我通过 rustc test1.rs 编译它时,我得到一个错误:

    error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'test1' 'test1.o' '-Wl,-force_load,/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-Wl,-dead_strip' '-nodefaultlibs' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-L' '/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin' '-L' '/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin'
ld: can't open output file for writing: test1, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error


$ rustc --version
rustc 1.0.0-dev

我看过一些与此相关的主题,但没有一个帮助我解决问题。

最佳答案

我在 Mac 上编译 Rust 时遇到了三个问题:

首先:如果您对通过 ld 写入文件/目录有任何问题,只需删除该文件并尝试重新编译。我不知道为什么,但在 Mac 上时常会出现此问题。

第二:如果您有其他ld 错误(与文件访问无关):尝试将以下部分添加到您的~/.cargo/config(如果您没有此文件,请随意创建):

[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

第三:有时您的 Mac 缺少一些开发工具/依赖项。使用以下命令自动安装其中最重要的部分:

xcode-select --install

关于macos - 错误 : linking with `cc` failed: exit code: 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28124221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com