BlenderPythonRecipes
BlenderPythonRecipes copied to clipboard
executing C code from python (windows)
hello_world.c
#include <stdio.h>
void hello_world() {
printf("Hello World!");
}
int main() {
return 0;
}
import ctypes
path = "C:\\Users\\zeffi\\compiles\\hello.so"
lib = ctypes.cdll.LoadLibrary(path)
lib.hello_world()
"""
gcc -c hello_world.c
>>> makes: hello_world.o
gcc -shared hello_world.o -o hello.so
>>> makes: hello.so
"""
from http://python.net/crew/theller/ctypes/tutorial.html and https://stackoverflow.com/questions/4145775
import ctypes
pyarr = [1, 2, 3, 4]
arr = (ctypes.c_int * len(pyarr))(*pyarr)