Cnbaby 发表于 2017-4-24 12:33:43

swig官方学习笔记(c++ and python)

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

 测试
  python
  >>> import test
  >>> test.go()
  GOGOGOG
  0

问题
  使用swig 1.x在g++ test_wrap.c的时候报错“invalid conversion from ‘const char*’ to ‘char*”,安装新版3.x后问题解决。
  --end
页: [1]
查看完整版本: swig官方学习笔记(c++ and python)