Could not compile rand_core or winapi

I am just learning rust and following the initial tutorial. No trouble building and running 'Hello, world!". Then I went on to using cargo to run the guessing game. I added rand = "0.5.5" to the dependencies (I also tried 0.5.6) and received the following when I tried cargo build....

Compiling rand_core v0.4.2
Compiling winapi v0.3.8
Compiling rand_core v0.3.1
error: failed to build archive: no such file or directory

error: aborting due to previous error

error: could not compile rand_core.

To learn more, run the command again with --verbose.
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.

To learn more, run the command again with --verbose.
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.

I have no idea what to do now...thanks

It sounds like there is a problem with your Rust installation. Which OS are you using?

Windows 10 . I followed the installation instructions with rustup

Initial goolging of the "failed to build archive: no such file or directory" error indicates that cargo is unable to find some other program that it needs. Perhaps you need to change your PATH?

That message comes from rustc build_with_llvm(): src/librustc_codegen_llvm/back/archive.rs

So my guess is that Visual Studio is missing Windows SDK component, so it can't build a static library.

My path includes .cargo\bin, which I see includes the rustc and cargo executables.. Is there another directory that should also be in the path?

I downloaded and installed the WIndows SDK (https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/) but I get the same errors when I try to cargo build

Still in need of some guidance. I would love to learn rust, but it doesn't help that it gives me these cryptic messages and no way to fix things.

I found the problem. I guess cargo does not like the directory name with a % in it. But that was what the tutorial said to use. In any case, when I changed that to a normal name, everything worked out fine.

Could you let us know what tutorial or instruction mentioned a directory with a % symbol in it? Maybe there is an opportunity for us to clarify its wording to reduce the chance of confusion for someone else in the future.

What tutorial tells you to use a directory with a % in it?

Edit: eminence was faster.

https://doc.rust-lang.org/book/ch01-02-hello-world.html

In the section on creating a project directory....

For Windows CMD, enter this:

mkdir "%USERPROFILE%\projects"
cd /d "%USERPROFILE%\projects"
mkdir hello_world
cd hello_world

1 Like

This is specifically for Windows CMD, and not, for example, for Powershell. In fact, you could also substitute any other directory manually instead of using environment variable. But I agree, for one not familiar with these concepts this might look confusing.

Actually not true. I was using the powershell

Yes, and that's the problem: you were using instructions which work only in CMD, but executed them in Powershell.

AHA...I see what you mean. Anyway, all's well that ends well!!

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.