Stop cargo from deleting intermediate files

Hello,

I want to link a rust project manually for debugging reasons. I ran

RUSTC_LOG=rustc_codegen_ssa::back::link=info cargo build

to see what the link command is. But manually executing the shown command fails, because some of the files listed as arguments do not exist.

Apparently, cargo creates those intermediate files, then uses them for linking, then deletes them.

  1. Why?
  2. How can I stop cargo from deleting those files?

Example:

"cc" "-m64" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.10hjt5z95o07w92u.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.16aset8wakzg96i4.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.1im8i29xjc1xlphz.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.1rcypertovtr9bs6.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.1txps2ja7mpyzbkd.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.1ue1je4c1fx4djnx.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.2099fbcxqwgglq6n.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.27g2r5f61yqhkzem.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.290vn8n96l59njp.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.2m2u88rg16fbbp35.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.2vsffwtscon58sgr.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.2w4pbr0c9k74ekmn.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.2whyd7kxiynij9u0.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.304floqtq8qw13cr.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.30tsl4nxjm4szm8w.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.32flroelbdyi5ywc.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.38mne01w37dqpkr5.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3g4mj4gb21wgvrol.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3i13j47hejv35564.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3kd4jb1vv0dyg2mg.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3ke2lgu7spbyynj5.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3lst6y8f1wtaint9.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3od1t2o4sk5fazic.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.3rgxvhg245gxe7tm.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.44wrrmztue1u1k5l.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4b3bmt83pjqp7xhr.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4eb3mlqs7qdz4kg2.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4j2v1b4jxu28bsdv.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4luixo05j5ckqopn.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4mkenz9pn3ejmrs4.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4nwme0682lalh1dg.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4o773toiebg8o4yi.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4rjfz3gx13kelwmj.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4ymv96xy3wnv3wyp.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.5b2xofnqxtlfp2k6.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.5ewqbuuv3fntfkf6.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.80v2a0cn5sazg5v.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.klwa9iaj0ceim3t.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.r28xvivhi6m30oz.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.rszw456unjdadao.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.sdfki9xxziu5lch.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.xe529bvrbj7thds.rcgu.o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.4ph98dl9j2t801kp.rcgu.o" "-Wl,--as-needed" "-L" "/home/volker/Documents/rusttest/target/debug/deps" "-L" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-443e20b28eeed844.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-3e337470e099b116.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-10a87791239bd676.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-0e6cad6dd623d38e.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-9d05dd05a4d51b33.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-a60ff138fe1adfad.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-0e9344458c09713e.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-939385b13e387309.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e3ce420901586b53.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-546bece8dd1bea42.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-9b358af16d7d7aa1.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-554cd499fe1a3b52.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-fbad2f5de5fb5cb2.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-8fec8a74c706e4b4.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-020914c5936c5f85.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4896c4057dc9553a.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2a6a2797f7a73818.rlib" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0e3656b1fda5fd7b.rlib" "-Wl,--end-group" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1f103368fa522bc0.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/volker/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
$ file /home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.10hjt5z95o07w92u.rcgu.o                                                                                       master  
/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.10hjt5z95o07w92u.rcgu.o: cannot open `/home/volker/Documents/rusttest/target/debug/deps/rusttest-495cf1d0c87b3a32.10hjt5z95o07w92u.rcgu.o' (No such file or directory)

It is rustc which writes and deletes the intermediate files. You can pass -Csave-temps to prevent rustc from deleting them.

1 Like