printf doesn't output anything
google colab cell:
%%writefile my_functions.c
#include <stdio.h>
#include <stdlib.h>
void my_void_func() {
printf("my_void_func called from C!\n");
}
compiling:
!gcc -shared -fPIC -o my_functions.so my_functions.c
here goes python part :
import ctypes
libc = ctypes.CDLL("libc.so.6")
my_lib = ctypes.CDLL("./my_functions.so")
my_lib.my_void_func.restype = None
my_lib.my_void_func()
my_void_funcin C, and then load that library into Python and call the function from there? Also, you're declaringlibcbut not doing anything with it - is that intentional?wurlitzerto catch and redirect output fromprintf()but sometime it works for me and sometimes not. It is answer from 2021 and maybe it needs something more. When calling printf by ctypes, jupyter does not show output from printf - Notebook - Jupyter Community Forum. I tested it only with localJupyter Lab