Dup Goto 📝

CtypesBasics

PT2/lang/python/ctypes 07-31 13:46:47
To Pop
24 lines, 57 words, 391 chars Monday 2023-07-31 13:46:47

Absolute Minimal Example

This is on Linux. As I write this I'm not sure how things are different with Windows, Cygwin and macos.

The C (in mylib.c):

#include <stdio.h>

void print_number(int n) {
  printf("%d\n",n);
}

Compile with

gcc -shared -o mylib.so mylib.c

The Python

import ctypes
lib = ctypes.cdll.LoadLibrary("./mylib.so")
lib.print_number(42)