Last active
April 16, 2018 04:20
-
-
Save lorepozo/0b087422ef03d6858e1a664e17ba3f6d to your computer and use it in GitHub Desktop.
Rust call C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* hello_world() { | |
printf("hello, world"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[link(name = "foo")] | |
extern "C" { | |
fn hello_world() -> (); | |
} | |
fn main() { | |
unsafe { hello_world(); } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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