Skip to content

Instantly share code, notes, and snippets.

@aisamanra
Created February 13, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aisamanra/2e1285fd662af649cfc32087b77f38d5 to your computer and use it in GitHub Desktop.
Save aisamanra/2e1285fd662af649cfc32087b77f38d5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
extern int add(int, int);
int
main(int argc, char* argv[])
{
printf("2 + 3 = %d\n", add(2, 3));
return 0;
}
main: libsample.a
gcc -lpthread -ldl main.c libsample.a -o main
libsample.a: sample.rs
rustc --crate-type=staticlib sample.rs
clean:
rm -f main libsample.a
#[no_mangle]
pub extern "C" fn add(x: isize, y: isize) -> isize {
x + y
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment