Rust dependencies problem

when i add crate like rand or syn in Cargo.toml and then do "cargo build",
the error "failed to build archive: no such file or directory"
"aborting due to previous error "
"could not compile rand_core" shows up.

I try to reinstall rust and cargo but this problem still exist.
Does anyone know how to fix this?

I need to self-learn rust within 1 week for my intern :frowning:

Do you have a C compiler installed? Rust uses cc for linking on most platforms, or MSVC link on Windows. Can you post the complete output of cargo build --verbose?

1 Like

This is my complete output:

PS C:\Users\user\%USERPROFILE%\projects\hello_cargo> cargo build --verbose
   Compiling rand_core v0.4.2
   Compiling winapi v0.3.8
     Running `rustc --crate-name rand_core C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\rand_core-0.4.2\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg "feature=\"alloc\"" --cfg "feature=\"std\"" -C metadata=662fd75f1d8e1549 -C extra-filename=-662fd75f1d8e1549 --out-dir C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps -L dependency=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps --cap-lints allow`
     Running `C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\build\winapi-59d810bd36b176f3\build-script-build`
     Running `rustc --crate-name winapi C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.3.8\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C 
debuginfo=2 --cfg "feature=\"minwindef\"" --cfg "feature=\"ntsecapi\"" --cfg "feature=\"profileapi\"" --cfg "feature=\"winnt\"" -C metadata=a019b11ca557d4d1 -C extra-filename=-a019b11ca557d4d1 --out-dir C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps -L dependency=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps --cap-lints allow --cfg "feature=\"ktmtypes\"" --cfg "feature=\"lsalookup\"" --cfg "feature=\"subauth\"" --cfg "feature=\"wincred\"" --cfg "feature=\"vcruntime\"" --cfg "feature=\"ntdef\"" --cfg "feature=\"basetsd\"" --cfg "feature=\"windef\"" 
--cfg "feature=\"sspi\"" --cfg "feature=\"guiddef\"" --cfg "feature=\"excpt\"" -l dylib=advapi32 -l dylib=credui -l dylib=kernel32 -l dylib=secur32`
   Compiling rand_core v0.3.1
     Running `rustc --crate-name rand_core C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\rand_core-0.3.1\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg "feature=\"alloc\"" --cfg "feature=\"std\"" -C metadata=578a540634d5088a -C extra-filename=-578a540634d5088a --out-dir C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps -L dependency=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps --extern rand_core=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps\librand_core-662fd75f1d8e1549.rmeta --cap-lints allow`
error: failed to build archive: no such file or directory

error: aborting due to previous error

error: could not compile `rand_core`.

Caused by:
  process didn't exit successfully: `rustc --crate-name rand_core C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\rand_core-0.3.1\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg "feature=\"alloc\"" --cfg "feature=\"std\"" -C metadata=578a540634d5088a -C extra-filename=-578a540634d5088a --out-dir C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps -L dependency=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps --extern rand_core=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps\librand_core-662fd75f1d8e1549.rmeta --cap-lints allow` (exit code: 1)       
warning: build failed, waiting for other jobs to finish...
error: failed to build archive: no such file or directory

error: aborting due to previous error

error: could not compile `rand_core`.

Caused by:
  process didn't exit successfully: `rustc --crate-name rand_core C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\rand_core-0.4.2\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg "feature=\"alloc\"" --cfg "feature=\"std\"" -C metadata=662fd75f1d8e1549 -C extra-filename=-662fd75f1d8e1549 --out-dir C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps -L dependency=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps --cap-lints allow` (exit code: 1)
warning: build failed, waiting for other jobs to finish...
error: failed to build archive: no such file or directory

error: aborting due to previous error

error: could not compile `winapi`.

Caused by:
  process didn't exit successfully: `rustc --crate-name winapi C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.3.8\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg "feature=\"minwindef\"" --cfg "feature=\"ntsecapi\"" --cfg "feature=\"profileapi\"" --cfg "feature=\"winnt\"" -C metadata=a019b11ca557d4d1 -C extra-filename=-a019b11ca557d4d1 --out-dir C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps -L dependency=C:\Users\user\%USERPROFILE%\projects\hello_cargo\target\debug\deps --cap-lints allow --cfg "feature=\"ktmtypes\"" --cfg "feature=\"lsalookup\"" --cfg "feature=\"subauth\"" --cfg "feature=\"wincred\"" --cfg "feature=\"vcruntime\"" --cfg "feature=\"ntdef\"" --cfg "feature=\"basetsd\"" --cfg "feature=\"windef\"" --cfg "feature=\"sspi\"" --cfg "feature=\"guiddef\"" --cfg "feature=\"excpt\"" -l dylib=advapi32 -l dylib=credui -l dylib=kernel32 -l dylib=secur32` (exit code: 1)

Note, you can wrap your code-like text in triple backticks to display it verbatim, like:

```
your text here
```

I'm afraid I don't use Windows much anymore, so I won't be much help to you. Do you at least have the MSVC tools installed? The book describes that requirement like so:

On Windows, go to https://www.rust-lang.org/tools/install and follow the instructions for installing Rust. At some point in the installation, you’ll receive a message explaining that you’ll also need the C++ build tools for Visual Studio 2013 or later. The easiest way to acquire the build tools is to install Build Tools for Visual Studio 2019. The tools are in the Other Tools and Frameworks section.

2 Likes

I try to use eclipse rather than vs code do the same thing and there is no error

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.