This commit is contained in:
2025-07-28 09:16:46 +08:00
parent 15764c8052
commit e5f835f5de
6 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
from ctypes import cdll
lib = cdll.LoadLibrary("libc.so.6") # Linux 系统
# lib = cdll.msvcrt # Windows 系统
# 调用 C 标准库中的 printf 函数,字符串需要编码为 bytes
message = b"Hello, ctypes!\n"
result = lib.printf(message)
print(result)

View File

@@ -0,0 +1,8 @@
from ctypes import cdll
lib = cdll.LoadLibrary('./example.so') # Linux 系统
# lib = cdll.LoadLibrary('./example.dll') # Windows 系统
# 调用 C 函数
result = lib.add_two_numbers(3, 5)
print(result)

View File

@@ -0,0 +1,3 @@
int add_two_numbers(int a, int b) {
return a + b;
}