import cffi ffi = cffi.FFI() libc = ffi.dlopen('libc.so.6') # Call C function from libc libc.printf(b"Hello, %s!\n", b"world")
import cffi ffi = cffi.FFI() # Declare function signature ffi.cdef(""" int add(int a, int b); """) # Load and compile C code lib = ffi.verify(""" int add(int a, int b) { return a + b; } """) # Call custom C function result = lib.add(2, 3) print(f"Result: {result}")This example uses cffi FFI new to create a new FFI object and then declares the signature of a C function called add that takes two integer arguments and returns an integer. The custom C code for the add function is then loaded and compiled using the verify method. Finally, the add function is called with the arguments 2 and 3 to print the result 5 to the console. Package Library: None (custom C code)