python调用c++

2021-09-30 18:15

阅读:1015

标签:std   imp   问题   导出   动态   python   efi   dll   python学习   C++代码 ctypes.cpp #include #ifdef _WIN32 #define LIB __declspec(dllexport) #else #define LIB #endif extern "C" LIB void CtypesDemo(int x,int y){ printf("公众号:Python学习开发%d %d\n",x,y); } 因为系统不同,调用方式不同 _WIN32:表示win32和win64 __declspec(dllexport)用于Windows中的动态库中,声明导出函数、类、对象等供外面调用。 extern "C" 的作用是让 C++ 编译器将 extern "C" 声明的代码当作 C 语言代码处理,可以避免 C++ 因符号修饰导致代码不能和C语言库中的符号进行链接的问题。 将C++文件编译成so文件 g++ -fPIC -shared -o ctypes ctypes.cpp Python代码 ctypes.py from ctypes import * lib=CDLL("ctypes") lib.CtypesDemo(3,4)python调用c++标签:std   imp   问题   导出   动态   python   efi   dll   python学习   原文地址:https://www.cnblogs.com/c-x-a/p/11945713.html


评论


亲,登录后才可以留言!