BlenderPythonRecipes icon indicating copy to clipboard operation
BlenderPythonRecipes copied to clipboard

executing C code from python (windows)

Open zeffii opened this issue 8 years ago • 1 comments

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
"""

zeffii avatar May 24 '17 18:05 zeffii

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)

zeffii avatar May 26 '17 09:05 zeffii