Skip to content

Instantly share code, notes, and snippets.

@alvesvaren
Created November 28, 2020 18:53
Show Gist options
  • Save alvesvaren/8b7eec01edd058e2edbaf3355caf4ee3 to your computer and use it in GitHub Desktop.
Save alvesvaren/8b7eec01edd058e2edbaf3355caf4ee3 to your computer and use it in GitHub Desktop.
Run C code from python
#include <stdio.h>
void say(char* message)
{
printf(message);
printf("\n");
}
int sum(int num1, int num2) {
return num1 + num2;
}
// Compile with: `gcc -fPIC -shared -o library.so library.c`
from ctypes import CDLL, c_char_p
from pathlib import Path
library = CDLL(Path().absolute() / "lib.so")
library.say(b"hejsan")
print(library.sum(10, 24))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment