I'm trying to use the cc crate to run a simple hello world c FFI as described in Build Script Examples - The Cargo Book
I've added a build.rs at the top of my project with
// Example custom build script.
fn main() {
// Tell Cargo that if the given file changes, to rerun this build script.
println!("cargo::rerun-if-changed=src/hello.c");
// Use the `cc` crate to build a C file and statically link it.
cc::Build::new()
.file("src/hello.c")
.compile("hello");
}
and I've added cc as a dependency using cargo add cc. However each time I try cargo build, i get the error
...
Compiling cc v1.2.18
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `cc`
--> build.rs:6:5
|
6 | cc::Build::new()
| ^^ use of unresolved module or unlinked crate `cc`
|
= help: if you wanted to use a crate named `cc`, use `cargo add cc` to add it to your `Cargo.toml`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `example` (build script) due to 1 previous error