error: linking with `cc` failed: exit code: 1
From your command rustc test1.rs
the compiler infers the name of the executable should be test1
. The linker tries to open this file so it can write the executable but fails with errno=21
whose stringified version is "Is a directory".
This suggests you have a directory in your working directory called test1
which is causing a conflict.
I was faced with three problems on Mac compiling Rust:
First: If you have any issue with writing files/dirs by ld
just remove that files and try to recompile. I don't know why, but on Mac this issue happens time to time.
Second: If you have other ld
errors (not about file access): try to add the following sections to your ~/.cargo/config
(if you don't have this file feel free to create):
[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",
]
Third: Sometimes your Mac lack of some dev tools/dependencies. Install the most important of them automatically with the command:
xcode-select --install