我有一个单 .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
我见过一些与这个相关的话题,但它们都没有帮助我解决这个问题。
发布于 2015-01-24 10:27:25
从命令rustc test1.rs
中,编译器推断可执行文件的名称应该是test1
。链接器试图打开这个文件,这样它就可以编写可执行文件,但是errno=21
失败了,它的字符串化版本是“是一个目录”。
这意味着您的工作目录中有一个名为test1
的目录,它导致了冲突。
发布于 2021-01-13 09:08:59
我面临着的三个问题,在Mac上编译Rust:
First:,如果您对ld
编写文件/ and有任何问题,只需删除该文件并尝试重新编译即可。我不知道为什么,但在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",
]
第三:有时缺少一些开发工具/依赖项。使用以下命令自动安装其中最重要的部分:
xcode-select --install
发布于 2021-07-12 07:48:27
如果您有“注意: /usr/bin/ld:找不到-lsqlite3”
然后安装libsqlite3-dev:$ sudo apt安装libsqlite3-dev
这是在Rust 1.53.0,Linux 20.2(基于Ubuntu20.04LTS)上工作的。
https://stackoverflow.com/questions/28124221
复制相似问题