Skip to content

Instantly share code, notes, and snippets.

@dpoulopoulos
Created September 21, 2021 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dpoulopoulos/6f682ba459620b58d306a548619789db to your computer and use it in GitHub Desktop.
Save dpoulopoulos/6f682ba459620b58d306a548619789db to your computer and use it in GitHub Desktop.
import ctypes
import pathlib
if __name__ == "__main__":
# load the lib
libname = pathlib.Path().absolute() / "libcadd.so"
c_lib = ctypes.CDLL(libname)
x, y = 6, 2.3
# define the return type
c_lib.cadd.restype = ctypes.c_float
# call the function with the correct argument types
res = c_lib.cadd(x, ctypes.c_float(y))
print(f"In Python: int: {x} float {y:.1f} return val {res:.1f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment