????3????????鰱????
???????????:
????python setup.py build
????????build??????boostCallTest1.so????????????????????????
????>>> import boostCallTest1
????>>> boostCallTest1.Max(1??3)
????3
???????swig???python
????SWIG??????????C????C++??д?????????????????????????????????????????????
????SWIG???????????????????????????y??????????????Perl?? PHP?? Python?? Tcl?? Ruby and PHP??
????swig?????? http://www.swig.org/download.html
???????????yum???????
????yum install swig
????1????д???????
???????????swigCall.cpp
???????????£?
????int Max(int i1??int i2)
????{
????return (i1>i2)?i1:i2;
????}
????2????д??????
???????????swigCall.i
???????????£?
????%module swigCall
????%{
????extern int Max(int i1??int i2);
????%}
????extern int Max(int i1??int i2);
????3????дMakefile???
???????????£?
????all:
????make swigCall
????swigCall:
????swig -python -c++ swigCall.i
????g++ -c swigCall.cpp swigCall_wrap.cxx -I/usr/include/python2.6/ -fPIC
????g++ -shared swigCall.o swigCall_wrap.o -o _swigCall.so
????clean:
????rm -f swigCall_wrap.c*
????rm -f *.py*
????rm -f *.so
????rm -f *.o
???????swig??????????-c++????????c++????
???????SIP???python
????SIP???SWIG???????????Python????C/C++???????? ????????SIP??voip?е?sip???????????????????sip?????python????voip?е?sip????????Э?飬?????????
???????
??????????python sip??
????1????дc++???
????1.1 ??д????
??????????? sipCall.h ????????
????class TestMode
????{
????public:
????int Max(int i1??int i2);
????};
????1.2 ??д???????
???????????sipCall.cpp ????????
????#include "sipCall.h"
????int TestMode::Max(int i1??int i2)
????{
????return (i1>i2)?i1:i2;
????}
????2????д??????
???????????sipCall.sip ????????
????%Module TestMode
????class TestMode {
????%TypeHeaderCode
????#include "sipCall.h"
????%End
????public:
????int Max(int i1??int i2);
????};
????3?????澲???
?????????y??????????????genlib.sh
????????????
????#! /bin/bash
????g++ -c -fPIC sipCall.cpp
????ar -crs libsipCall.a sipCall.o
????4????дconfigure???
?????y??????????Makefile?????????£?
????#! /usr/bin/env python
????import os
????import sipconfig
????build_file = "sipCall.sbf"
????config = sipconfig.Configuration()
????cmd = " ".join([config.sip_bin?? "-c"?? "."?? "-b"?? build_file?? "sipCall.sip"])
????os.system(cmd)
????makefile = sipconfig.SIPModuleMakefile(config?? build_file)
????makefile.extra_libs = ["sipCall"]
????makefile.LIBDIR.append(".")
????makefile.generate()
????5??????genlib.sh???????lib?????
????6??????configure.py???????Makefile??
????7??????make????????????so???????
????8??python???????£?
????>>> import TestMode
????>>> dir(TestMode)
????['TestMode'?? '__doc__'?? '__file__'?? '__name__'?? '__package__']
????>>> s = TestMode.TestMode()
????>>> s.Max(1??3)
????3