ultrasaurus / rust-clib

example of writing a library that can be called from C or Rust
MIT License
9 stars 3 forks source link

how to make example work? #1

Open ultrasaurus opened 4 years ago

ultrasaurus commented 4 years ago

I'd like to understand how to put crate at the root. I did an experiment (see branch crate-root, but I couldn't figure out syntax for including the lib. Probably something really basic I'm missing here...

cargo run --example stdin

output

   Compiling add v0.1.0 (/Users/sallen/src/rust/clib)
error[E0432]: unresolved import `add`
 --> examples/stdin.rs:1:5
  |
1 | use add::add;
  |     ^^^ use of undeclared type or module `add`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: could not compile `add`.
ultrasaurus commented 4 years ago

I don't think this had anything to do with moving crate to the root (since example still fails at master, when I reset history to before this change)

I think we need to tell cargo to build the c library and the rust library with two target crate types:

crate-type = ["staticlib", "lib"]