Macro error when trying to compile in a Virtual Box Linux

⚓ Rust    📅 2025-10-22    👤 surdeus    👁️ 9      

surdeus

I’m running macOS, and trying to cross compile for Linux. It’s been a pain. My latest attempt is using VirtualBox to run an Ubuntu system. After creating the Ubuntu 24 instance, I mounted my working directory in the Linux system as a shared folder, and then ran (within the virtual Linux):

cd /mnt/repo3
export CARGO_TARGET_DIR=/mnt/repo3/linux-target
cargo build -p my-web-site --lib  

The reason for the different target dir is that I don’t want it writing to ./target, which contains all the stuff being compiled from the host macOS system.

It ran and eventually died with this:

  Compiling serde_core v1.0.228
error: couldn't read `/mnt/repo3/linux-target/debug/build/serde_core-59bef16afe765c1f/out/private.rs`: No such file or directory (os error 2)
   --> /home/rob/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_core-1.0.228/src/crate_root.rs:165:9
    |
165 |         include!(concat!(env!("OUT_DIR"), "/private.rs"));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/rob/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_core-1.0.228/src/lib.rs:111:1
    |
111 | crate_root!();
    | ------------- in this macro invocation
    |
    = note: this error originates in the macro `include` which comes from the expansion of the macro `crate_root` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `serde_core` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

Those /home/rob/.cargo path is from the most macOS system. I don’t understand how it found it. The Linux system has it’s own ~/.cargo/registry directory. I see it downloaded serde there. Is there another environment variable to set, or something to make sure the linux system doesn’t try to use pieces of the outer host macOS system?

4 posts - 2 participants

Read full topic

🏷️ Rust_feed