//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