用 SWIG 生成 TidyLib 的 Python 扩展
2009-03-29 10:49
696 查看
用 SWIG 生成 TidyLib 的 Python 扩展
-----------------------------------------
Created by : Andrew.Wu
Created on : 2009/03/29
-----------------------------------------
一、
建立一个单独的工作目录, 复制 tidy/include 所有头文件到这个目录。以下文件也同在这个目录
二、
文件 pytidy.i
注意 pytidy.i 中的 %include "tidy2.h" 。 因为直接使用 %include "tidy.h" 编译时会有一些冲突, 所以增加了tidy2.h。tidy2.h 是 tidy.h 的 copy,只是注释了struct _TidyAllocatorVtbl 。
三、
文件 SContruct
四、
在 Visual Studio 2008 Command Prompt 使用 scons.py 编译
五、
import pytidy
六、
Tidy 是从 cvs 下载的,版本 $Date: 2008/12/07 21:08:48 $ $Revision: 1.45 $ (tidy/src/version.h)
SCons 版本 v1.2.0.d20090113.r3897 (scons.py --version)
SWIG 版本 swigwin-1.3.38
Python 版本 2.6.1
编译器 是 vc2008 + sp1
七、
另一个 tidy python 扩展 是mxTidy( http://www.egenix.com/products/python/mxExperimental/mxTidy/ ), 但目前只支持到python 2.5
-----------------------------------------
Created by : Andrew.Wu
Created on : 2009/03/29
-----------------------------------------
一、
建立一个单独的工作目录, 复制 tidy/include 所有头文件到这个目录。以下文件也同在这个目录
二、
文件 pytidy.i
%module "pytidy" %include "cpointer.i" %include "carrays.i" %{ #define _LIB 1 #define SUPPORT_UTF16_ENCODINGS 1 #define SUPPORT_ASIAN_ENCODINGS 1 #define SUPPORT_ACCESSIBILITY_CHECKS 1 #include "platform.h" #include "tidyenum.h" #include "buffio.h" #include "tidy.h" %} %include "platform.h" %include "tidyenum.h" %include "buffio.h" %include "tidy2.h" %pointer_functions(uint, uintp); %pointer_functions(char, charp); %pointer_functions(byte, bytep); %array_class(byte, byteArray); %array_class(char, charArray); %import tidy.h
注意 pytidy.i 中的 %include "tidy2.h" 。 因为直接使用 %include "tidy.h" 编译时会有一些冲突, 所以增加了tidy2.h。tidy2.h 是 tidy.h 的 copy,只是注释了struct _TidyAllocatorVtbl 。
三、
文件 SContruct
import os,shutil env = Environment() env.Append(ENV = os.environ) env.Append( CXXFLAGS = Split("/EHsc /MD"), CPPDEFINES = [ 'WIN32', '_WINDOWS', '_USRDLL', 'PYTIDY_EXPORTS', 'SUPPORT_UTF16_ENCODINGS', 'SUPPORT_ASIAN_ENCODINGS', 'SUPPORT_ACCESSIBILITY_CHECKS' ], CPPPATH = [ r'C:/Script/Python26/include', r'C:/libs/tidy/include' ], LIBPATH = [ r'C:/Script/Python26/libs', r'C:/libs/tidy/libs' ], LIBS = ['libtidy.lib'], SWIGFLAGS = ['-c++', '-python'], #SWIGFLAGS = ['-python'], SHLIBSUFFIX = [''] ); input_files = [ 'pytidy.i', ] s = env.SharedLibrary('_pytidy.dll', input_files) def DllToPyd(**v): dll = str(v["target"][0]); pyd = dll.replace(".dll", ".pyd"); shutil.move(dll, pyd) env.AddPostAction(s, env.Action(DllToPyd))
四、
在 Visual Studio 2008 Command Prompt 使用 scons.py 编译
五、
import pytidy
六、
Tidy 是从 cvs 下载的,版本 $Date: 2008/12/07 21:08:48 $ $Revision: 1.45 $ (tidy/src/version.h)
SCons 版本 v1.2.0.d20090113.r3897 (scons.py --version)
SWIG 版本 swigwin-1.3.38
Python 版本 2.6.1
编译器 是 vc2008 + sp1
七、
另一个 tidy python 扩展 是mxTidy( http://www.egenix.com/products/python/mxExperimental/mxTidy/ ), 但目前只支持到python 2.5
相关文章推荐
- 在VC++6.0中使用swig生成Python扩展的配置
- 使用SWIG实现C++扩展Python
- SWIG and Python(用SWIG将C/C++封装为Python扩展模块)
- Swig之cpp完整python扩展疑难对策
- 使用SWIG轻松编写Python扩展
- 多线程环境下用swig做python扩展库时的问题:如何做阻塞函数的扩展?
- 使用swig实现C++的python扩展功能
- 使用SWIG对Python进行扩展
- 使用swig从c/c++代码生成java/python/R/php...代码
- C++ Boost 之Python(生成一个扩展模块)
- python 中用SWIG包装C和C++和接口生成的例子
- centos7下使用swig扩展python接口来调用c++ 实现声纹识别
- 通过SWIG用C语言编写Python扩展
- 29. Python脚本学习笔记二十九 扩展Python以及SWIG
- 高效开发Python扩展模块方法:用SWIG封装C/C++代码
- Swig之cpp完整python扩展疑难对策
- 使用swig进行C/C++对Python的扩展
- 高效开发Python扩展模块方法:用SWIG封装C/C++代码
- windows下swig 写python扩展的麻烦事
- 使用SWIG来扩展Python