我不知道如何将C库链接到Rust.以下是我所做的:
我的lib.rs文件包含
#[link(name = "test")]
extern {
该图书馆已建成,名称为libtest.a
.
我不知道该把它放在哪里.我试过好几个地方,但我在做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
我不知道该把libtest.a放在哪里,这样/usr/bin/ld
才能找到它.Cargo没有告诉我项目中图书馆应该在哪里.
我的Cargo.toml包含
[dependencies.test]
path = "./src/test"
[dependencies]
bitflags = "0.7"
libc = "0.2"
[build-dependencies]
make-cmd = "0.1"
在再次阅读the FFI section of the documentation之后,我认为以前的错误消息可能是因为我正在寻找一个共享库,所以我做了以下更改:
#[link(name = "test", kind = "static")]
在这些更改之后,我仍然不知道如何指示库的位置,但消息现在告诉我:
error: could not find native static library `test`, perhaps an -L flag is missing?