Error: could not execute process `target/debug/hello` (never executed)

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:

  1. Deleted the ~/.cargo directory
  2. Kept the ~/.rustup directory
  3. 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.

I suspect this might be caused by compiling under /tmp.

If this was on Windows, I would suggest checking if overly enthusiastic antivirus software has deleted the executable between the time rustc finishes compiling it and cargo tries to invoke it, but Linux machines don't normally have that problem :thinking:

It does not matter where I compile. I get the same result under the home dir (~/).

If you haven't, you might want to check the cargo run --verbose output just to see if there's anything unexpected in there.

1 Like

Thanks for the tip. Here's the output I get.

~/hello$ RUST_BACKTRACE=1 cargo run --verbose
   Compiling hello v0.1.0 (/home/sylvain/hello)
     Running `rustc --crate-name hello --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=3b6fcb9eb129c0f3 -C extra-filename=-3b6fcb9eb129c0f3 --out-dir /home/sylvain/hello/target/debug/deps -C incremental=/home/sylvain/hello/target/debug/incremental -L dependency=/home/sylvain/hello/target/debug/deps`
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/hello`
error: could not execute process `target/debug/hello` (never executed)

Caused by:
  No such file or directory (os error 2)

Is there a binary named /home/sylvain/hello/target/debug/deps/hello-<somehash>?

Only one with a .d file extension.

$ ls target/debug/deps/
hello-3b6fcb9eb129c0f3.d

When I run cargo build in a docker container (using the same rust bin on my host), there is one:

root@09b1e78bc687:/usr/src/hello# ls target/debug/deps/
hello-3b6fcb9eb129c0f3  hello-3b6fcb9eb129c0f3.d

Strange issue you have. Have you developed other things on this system before you tried rust? Maybe something in your user configs is borked?

Could you perhaps make a create a dummy account, fresh username. And in this dummy user account do rustup and install rust. Then try your compile.
It is a little extra running around, but if it compiles on a fresh username account then you know your system is OK. If a fresh username still gives you the same problem then you have a system wide issue.