Skip to content

Instantly share code, notes, and snippets.

@lorepozo
Last active April 16, 2018 04:20
Show Gist options
  • Save lorepozo/0b087422ef03d6858e1a664e17ba3f6d to your computer and use it in GitHub Desktop.
Save lorepozo/0b087422ef03d6858e1a664e17ba3f6d to your computer and use it in GitHub Desktop.
Rust call C
void* hello_world() {
printf("hello, world");
}
#[link(name = "foo")]
extern "C" {
fn hello_world() -> ();
}
fn main() {
unsafe { hello_world(); }
}
default:
gcc -g -c foo.c -o foo.o
ar rcs libfoo.a foo.o
rustc main.rs -L .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment