跟随官方教程
1. 编写C文件example.c
#include <time.h> double My_variable = 3.0; int fact(int n) { if (n <= 1) return 1; else return n*fact(n-1); } int my_mod(int x, int y) { return (x%y); } char *get_time() { time_t ltime; time(<ime); return ctime(<ime); }
2. 编写接口文件 example.i
%module example %{ /* Put header files here or function declarations like below */ extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); %} extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time();
3. 生成python接口文件——example.py、 example_wrap.c
swig -python example.i
4. 编译C文件
#这里官方教程没跑成功,自己find下路径
gcc -c example.c example_wrap.c -fpic -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/
ld -shared example.o example_wrap.o -o _example.so
gcc -c example.c example_wrap.c -fpic -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/
ld -shared example.o example_wrap.o -o _example.so
5. 运行
启动python(!!这里要使用和上面匹配的python版本)
>>> import example >>> example.fact(5) 120 >>> example.my_mod(7,3) 1
--end
相关推荐
swig的学习以及国密的python封装
Python & C++ Comparisons Python C API SWIG
cmake_c++_python_swig
swig工具,C/C++到python, tcl 的接口
swig 打包C/C++程序;供python调用。 本软件操作平台windows 10 Vs2017;python3.8; 主要讲述swig vs配置,测试用例。 主要包含常量,变量,指针,结构体定义及运用。
用swig实现在python中使用c++的函数和类的很少的介绍的文章
windows 上的 Python+ M2Crypto+Openssl+Swig 集成环境,已经集成了openssl 的相关包, 配置python 跟 swig 的环境变量即可运行, 另外python27.dll 需放入System32 , 64 位系统为SysWOW64
基于SWIG的Python仪器驱动封装技术.pdf
java调用dll java调用c,采用swig,官方实例,对官方代码中不能通过的地方做了修改和说明,有开发过程描述。
SWIG能应用于各种不同类型的语言包括常用脚本编译语言例如Perl, PHP, Python, Tcl, Ruby and PHP。支持语言列表中也包括非脚本编译语言,例如C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Modula-3, ...
对开发人员的一个常见要求是向脚本语言接口公开 C/C++ 代码,这正是 Simplified Wrapper and Interface Generator (SWIG) 的用武之地。SWIG 允许您向广泛的脚本语言公开 C/C++ 代码,包括 Ruby、Perl、Tcl 和 Python...
swig-3.0.12-windows版本安装包
swig-4.0.2-windows版本安装包
基于SWIG的Python仪器驱动封装技术
SWIG-4.0.2官方版本,由于有时官网上不了,放在这里方便使用 SWIG Version 4.0.2 Compiled with i686-w64-mingw32-g++ [i686-w64-mingw32] Configured options: +pcre
进行嵌入联接的开发工具
SWIG软件开发工具,适用于将C\C++转换成C#、python等高级语言
SWIG is a software development tool that simplifies the task of interfacing different languages to C and C++ programs. In a nutshell, SWIG is a compiler that takes C/C++ declarations and creates the ...
SWIG,SIP常用于将C语言编写的程序库转化为Python模块。Boost C++ Libraries包含了一组库,Boost.Python,使得以 Python 或 C++ 编写的程序能互相调用。借助于拥有基于标准库的大量工具、能够使用低级语言如C和可以...