I'm wanting to export my C++ classes as a library. I know this cannot be done easily since names are munged. I know you can export C functions from C++. I had heard that Swig may be what I'm looking for. I see that Swig can export C++ to C. I'm wondering if Swig also has the ability to then wrap those C functions in a header-only C++ file. I'm looking for something like this:
This base code:
class Point {
public:
Point(int x,int y);
int getX();
int getY();
}
Transforms into this C Code:
CPoint* CPoint_alloc(int x,int y);
int CPoint_getX(CPoint* p);
int CPoint_getY(CPoint* p);
Then the following C++ header would be generated to wrap the C code:
class Point {
CPoint* p;
public:
Point(int x,int y){
p = Point_alloc(x,y);
}
int getX(){
return CPoint_getX(p);
}
int getY(){
return CPoint_getY(p);
}
}
Can Swig generate the C++ header? Or is there some other tool I can use?
Thanks