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

2 篇文章 0 订阅

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值