Skip to content

Instantly share code, notes, and snippets.

@lbolla
Created August 28, 2013 08:56
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 lbolla/6363780 to your computer and use it in GitHub Desktop.
Save lbolla/6363780 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void foo() {
printf("Hello world\n");
}
int bar() {
return 1;
}
int baz(int n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += i;
}
return sum;
}
import ctypes
libgo = ctypes.cdll.LoadLibrary('./libgo.so')
libgo.foo()
print(libgo.bar())
print(libgo.baz(100))
all: go.so
go.o: go.c
gcc -std=c99 -c -fPIC go.c -o go.o
go.so: go.o
gcc -shared -Wl,-soname,libgo.so -o libgo.so go.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment