swig c++ 生成python java 调用代码

这篇博客介绍了如何利用Swig工具将C++代码生成Python和Java的调用接口。详细步骤包括编写C++源码、头文件以及Swig接口文件,然后通过特定的编译命令生成对应的Java和Python接口。在过程中,作者遇到了一些问题,如符号未定义错误和Python模块导入问题,并给出了相应的解决办法。
摘要由CSDN通过智能技术生成

 

//hello.cpp

#include "hello.h"

void testClass::hei(){
    cout << "hello world!!"<<endl;
}

int testClass::testAdd(int a, int b) {
    return a+b;
}

 

//hello.h

 

#include <iostream>
using namespace std;

class testClass
{
public:
    void hei();
    int testAdd(int a,int b);
};

//test.i

 

%module testHello //这是要生成的模块名
%{
#include "hello.h"
%}

%include "hello.h"

 

生成java接口终端下运行:

swig -c++ -java test.i

g++ -c -fpic hello.cpp

g++ -c -fpic test_wrap.cxx -I{jni.h 和 jni_md.h头文件的目录}

g++ -shared -fpic hello.o test_wrap.o -o libexample.so

生成Python接口终端下运行:

swig -c++ -python test.i

g++ -c -fpic hello.cpp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值