[Python] printf (inside C code) called from python in google colab. (no output)

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    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()

    Continue reading...

Compartilhe esta Página