美文网首页Python
[Python]python中调用C的.so代码

[Python]python中调用C的.so代码

作者: _小老虎_ | 来源:发表于2018-08-03 16:27 被阅读3次

1.c模块

helloworld.c
#include<stdio.h>
int test() {
    printf("hello world!\n");
    return 0;
}
complie.sh编译
gcc helloWorld.c -fPIC -shared -o libhello.so

2.Python main.py

import ctypes
so = ctypes.CDLL("./libhello.so")
so.test()
运行
python main.py

hello world!

相关文章

网友评论

    本文标题:[Python]python中调用C的.so代码

    本文链接:https://www.haomeiwen.com/subject/unquvftx.html