python讲解from ctypes import *调用C语言动态链接库


前言

在这里插入图片描述顾名思义

一、from ctypes import *

在写python程序时,有时会用到C语言库函数

Python 的 ctypes 要使用 C 函数,需要先将 C 编译成动态链接库的形式,即 Windows 下的 .dll 文件,或者 Linux 下的 .so 文件。

Windows 系统下的 C 标准库动态链接文件为 msvcrt.dll (一般在目录 C:\Windows\System32 和
C:\Windows\SysWOW64 下分别对应 32-bit 和 64-bit,使用时不用刻意区分,Python 会选择合适的)

Linux 系统下的 C 标准库动态链接文件为 libc.so.6 (以 64-bit Ubuntu 系统为例, 在目录
/lib/x86_64-linux-gnu 下)

libc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")

二、调用举例

1.代码

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45556441/article/details/114133979
今日推荐