Running into issues compiling rust projects, on Ubuntu 22.04, with rustc 1.65.
The problem happens with the simplest hello world project, e.g.:
$ cargo new hello
$ cd hello
$ cargo run
Compiling hello v0.1.0 (/tmp/hello)
Finished dev [unoptimized + debuginfo] target(s) in 0.29s
Running `target/debug/hello`
error: could not execute process `target/debug/hello` (never executed)
Caused by:
No such file or directory (os error 2)
The executable, hello
, expected to be under ./target/debug/hello
is not there. Only hello.d
is there.
I have tried uninstalling and re-installing rust but the problem persists. I installed rust with rustup (i.e.: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
).
In case that can help, doing the following will work. Run a docker container, and mount the host .cargo
directory and the ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu
directory (rustc --print sysroot
).
$ docker run --rm -it -v ~/.cargo:/.cargo -e CARGO_HOME=/.cargo -v `rustc --print sysroot`:/rust:ro -e PATH=$PATH:/rust/bin ubuntu:22.04 bash
In the container, install gcc
and create the toy project, and run it.
apt update && apt install -y gcc
cargo new hello
cd hello
cargo run
Compiling hello v0.1.0 (/hello)
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/hello`
Hello, world!
Another thing I tried:
- Deleted the
~/.cargo
directory - Kept the
~/.rustup
directory - Prepended the PATH with
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin
such that:
$ which rustc
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc
$ which cargo
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo
But it makes no difference, same problem.