Simple C lib calls from Python
1import ctypes
2import os
3
4class HelloWorld:
5 def __init__(self):
6 # Obtener la ruta correcta al .so del submódulo
7 self.lib_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib', 'build', 'lib', 'libhello.so')
8 self.lib = ctypes.CDLL(self.lib_path)
9 self.lib.hello.restype = ctypes.c_char_p
10
11 def greet(self):
12 return self.lib.hello().decode('utf-8')