I do not know how to link a C library to Rust. Here's what I have done:
My lib.rs file contains
#[link(name = "test")]
extern {
The library is built and has the name libtest.a
.
I do not know where to put it. I have tried several places, but I still have errors of this type when doing cargo run
error: linking with `cc` failed: exit code: 1
//..
note: /usr/bin/ld: no se puede encontrar -ltest
note: /usr/bin/ld: no se puede encontrar -ltest
note: /usr/bin/ld:.......
//..
Translation of the above /usr/bin/ld: no se puede encontrar -ltest
-> usr/bin/ld: cannot find -ltest
I do not know where to put libtest.a so that /usr/bin/ld
can find it. Cargo does not tell me where the library should be in the project.
My Cargo.toml contains
[dependencies.test]
path = "./src/test"
[dependencies]
bitflags = "0.7"
libc = "0.2"
[build-dependencies]
make-cmd = "0.1"
After reading the FFI section of the documentation again, I thought that maybe the error messages from before were because I was looking for a shared library, so I made the following changes:
#[link(name = "test", kind = "static")]
After these changes, I still do not know how to indicate where the library is, but the message now tells me this:
error: could not find native static library `test`, perhaps an -L flag is missing?