Using multiple .c source files with Rust
I am using a file successfully .c
with Rust ( see this answer ). How can I link multiple files .c
? I've already tried #![link_args="/c_src/*.c"]
with no luck.
- rust-demo
- src
- c_src
- file1.c
- file2.c
- etc...
- main.rs
Edit:
I think the best question is, how can I just delete the C source code in my Rust directory and start using it directly using the Rust attribute link
and extern
(or any other way) with the above example in mind?
source to share
how can I just delete the C source code in my Rust directory and start using it directly using the Rust attribute
link
andextern
(or any other way)
You can't just type C code into the Rust sources and expect it to work. As stated in the comments to your other question, the syntax is #![link_args="foo.c"]
never planned to work and you shouldn't rely on it.
The only thing that Rust code can be tied to (other than other rust code) is a compiled library (static or dynamic). You need to compile your C files into one or more libraries before you can call them from Rust code.
The correct way to do this is to add an argument build
in a section of [package]
yours Cargo.toml
, so you can call a makefile that will build your C files in a static library first and then link your code to rust against it.
All data is presented on the truck website: http://doc.crates.io/build-script.html
source to share