Add some C code.
This commit is contained in:
parent
c0dc9e794e
commit
91ab5ced3c
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
/target
|
/target
|
||||||
main
|
main
|
||||||
.idea
|
.idea
|
||||||
|
*.o
|
||||||
|
*.so
|
5
build
Executable file
5
build
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cc -c src/test.c
|
||||||
|
cc -shared test.o -o libtest.so
|
||||||
|
rustc -l test -L . src/main.rs
|
@ -18,6 +18,10 @@ impl Greeter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn print_num(num: i32);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
Greeter::new("Hello, Jesse!").greet();
|
Greeter::new("Hello, Jesse!").greet();
|
||||||
|
|
||||||
@ -42,4 +46,8 @@ fn main() {
|
|||||||
bst.insert(0);
|
bst.insert(0);
|
||||||
println!("{:?}", bst);
|
println!("{:?}", bst);
|
||||||
println!("find result: {:?}", bst.find(0));
|
println!("find result: {:?}", bst.find(0));
|
||||||
|
|
||||||
|
// calling some C
|
||||||
|
let find_result = bst.find(3).unwrap_or(-1);
|
||||||
|
unsafe { print_num(find_result); }
|
||||||
}
|
}
|
||||||
|
5
src/test.c
Normal file
5
src/test.c
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void print_num(int num) {
|
||||||
|
printf("[from c]: num is %d\n", num);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user