`
heipark
  • 浏览: 2077846 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics