Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clib.so: clib.o | |
gcc -shared -o clib.so clib.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
# A. Create library | |
C_library = ctypes.CDLL("clib.so") | |
# B. Specify function signatures | |
hello_fxn = C_library.say_hello | |
hello_fxn.argtypes = [ctypes.c_int] | |
# C. Invoke function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void say_hello(int times) | |
{ | |
for (int i = 0; i < times; ++i) | |
{ | |
printf("%d. Hello, Python. I am C!\n", i+1); | |
} | |
} |
NewerOlder