test.cpp
#include <iostream> int go() { std::cout << "GOGOGOG" << std::endl; return 0; } int main(int argc, char **argv) { go(); }
test.i
%module test %{ /* Put header files here or function declarations like below */ extern int go(); %} extern int go();
编译
swig -python test.i
g++ -fPIC -c test.cpp -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/
g++ -fPIC -c test_wrap.c -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/
g++ test_wrap.o test.o -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/ -shared -fPIC -o _test.so
g++ -fPIC -c test.cpp -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/
g++ -fPIC -c test_wrap.c -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/
g++ test_wrap.o test.o -I/home/tools/Python-2.7.9/Include/ -I/home/tools/Python-2.7.9/ -shared -fPIC -o _test.so
测试
python
>>> import test
>>> test.go()
GOGOGOG
0
问题
使用swig 1.x在g++ test_wrap.c的时候报错“invalid conversion from ‘const char*’ to ‘char*”,安装新版3.x后问题解决。
--end
相关推荐
swig的学习以及国密的python封装
Python & C++ Comparisons Python C API SWIG
swig 打包C/C++程序;供python调用。 本软件操作平台windows 10 Vs2017;python3.8; 主要讲述swig vs配置,测试用例。 主要包含常量,变量,指针,结构体定义及运用。
cmake_c++_python_swig
swig工具,C/C++到python, tcl 的接口
用swig实现在python中使用c++的函数和类的很少的介绍的文章
对开发人员的一个常见要求是向脚本语言接口公开 C/C++ 代码,这正是 Simplified Wrapper and Interface Generator (SWIG) 的用武之地。SWIG 允许您向广泛的脚本语言公开 C/C++ 代码,包括 Ruby、Perl、Tcl 和 Python...
In a nutshell, SWIG is a compiler that takes C/C++ declarations and creates the wrappers needed to access those declarations from other languages including including Perl, Python, Tcl, Ruby, Guile, ...
使用Swig转换C++库到C#示例代码, 包含了示例的动态库和对应的代码 打包了应用程序 示例用法,提供参考
NULL 博文链接:https://cherishlc.iteye.com/blog/1689224
android studio 使用NDK和swig编译c++示例。使用swig可以自动化编译c++函数。比较方便。http://blog.csdn.net/qq_16064871
SWIG能应用于各种不同类型的语言包括常用脚本编译语言例如Perl, PHP, Python, Tcl, Ruby and PHP。支持语言列表中也包括非脚本编译语言,例如C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Modula-3, ...
C#利用SWIG调用C++的DLL示例程序,利用SWIG可以方便的在C#和C++之间架起沟通的桥梁。详见https://www.cnblogs.com/sinceret/p/14012099.html
配置环境变量JAVA_BIN和JAVA_INCLUDE。比如: ...工程“属性” -> C/C++ -> 常规 -> 调试信息格式,选择“程序数据库(/Zi)”。 “生成”64位版本。 打开win10控制台,进入simple,运行”java runme“。
https://sourceforge.net/projects/swig/files/swig/swig-4.2.0/
windows 上的 Python+ M2Crypto+Openssl+Swig 集成环境,已经集成了openssl 的相关包, 配置python 跟 swig 的环境变量即可运行, 另外python27.dll 需放入System32 , 64 位系统为SysWOW64
基于SWIG的Python仪器驱动封装技术.pdf
python调用C/C++有不少的方法,如boost.python, swig, ctypes, pybind11等,这些方法有繁有简,而pybind11的优点是对C++ 11支持很好,API比较简单,现在我们就简单记下Pybind11的入门操作。 1. pybind11简介与环境...
swig-3.0.12-windows版本安装包