-1

I have searched Stackoverflow and the internet far and wide for an answer to my problem but have found no fix yet. I have written a program in rust using the crates 'rand' and 'matrix'. I have added both using cargo, and added the lines

extern crate rand;
extern crate matrix;

use rand::prelude::*;
use matrix::prelude::*;

This error occurs:

error[E0463]: can't find crate for `rand`
 --> main.rs:1:1
  |
1 | extern crate rand;
  | ^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `matrix`
 --> main.rs:2:1
  |
2 | extern crate matrix;
  | ^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0433]: failed to resolve: use of undeclared type `Compressed`
  --> main.rs:45:49
   |
45 |     let mut m1: matrix::prelude::Compressed<i32> = Compressed::zero((5,5));
   |                                                    ^^^^^^^^^^ use of undeclared type `Compressed`

error[E0433]: failed to resolve: use of undeclared type `Compressed`
  --> main.rs:46:49
   |
46 |     let mut m2: matrix::prelude::Compressed<i32> = Compressed::zero((5,5));
   |                                                    ^^^^^^^^^^ use of undeclared type `Compressed`

error[E0433]: failed to resolve: use of undeclared type `Compressed`
  --> main.rs:47:49
   |
47 |     let mut m3: matrix::prelude::Compressed<i32> = Compressed::zero((5,5));
   |                                                    ^^^^^^^^^^ use of undeclared type `Compressed`

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0433, E0463.
For more information about an error, try `rustc --explain E0433`.

My cargo.toml contains the following:

[package]
name = "mat_mult"
version = "0.1.0"
edition = "2021"

[dependencies]
matrix = "0.22.0"
rand = "0.8.5"

When I do cargo build the program runs and works fine without errors, these errors only occur when attempting to compile with rustc main.rs. It is important for me to be able to compile the program because I would like to run it on a remote system on which I am unable to install cargo.

Any indications of something that I am missing?

Chuckster
  • 69
  • 1
  • 4
  • 1
    How are you trying to build/run your program? – kmdreko Aug 28 '23 at 14:35
  • Is this with `cargo build`? – tadman Aug 28 '23 at 14:55
  • I've editted my question. The program works when I do ```cargo build```, but when I try to do ```rustc main.rs``` it gives me these errors. – Chuckster Aug 28 '23 at 16:14
  • Please provide the full error from the build. Please read [complete error message](https://meta.stackoverflow.com/questions/359146/why-should-i-post-complete-errors-why-isnt-the-message-itself-enough) – aled Aug 28 '23 at 16:21
  • 2
    Prefer using Cargo to build your project with dependencies, otherwise you have to build and link them all yourself, which is not easy. _"It is important for me to be able to compile the program because I would like to run it on a remote system"_ In that case you would [cross-compile](https://rust-lang.github.io/rustup/cross-compilation.html) your program, not abstain from using Cargo. See also [cross](https://github.com/cross-rs/cross). – E_net4 Aug 28 '23 at 16:42

0 Answers0