Skip to content

Instantly share code, notes, and snippets.

@jonfk
Created July 22, 2015 03:49
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 jonfk/876b1d9b82139b10d80d to your computer and use it in GitHub Desktop.
Save jonfk/876b1d9b82139b10d80d to your computer and use it in GitHub Desktop.
python c ffi
all:
gcc -shared -Wl,-soname,testlib -o testlib.so -fPIC testlib.c
clean:
rm testlib.so
#include <stdio.h>
void myprint(void);
int add(int , int );
int add(int a, int b) {
return a + b;
}
void myprint()
{
printf("hello world\n");
}
#!/usr/bin/env python3
import ctypes
testlib = ctypes.CDLL('./testlib.so')
testlib.myprint()
a = testlib.add(5,2)
print(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment