[Mono-dev] C++ wrapper ?
William S Fulton
wsf at fultondesigns.co.uk
Sun Sep 4 04:17:06 EDT 2005
ivar at imaker.no wrote:
> If I want to wrap a c++ class library what should I do ?
> For me it seems like I have to do the following:
> 1. Make a ANSI c interface file calling the C++ functions, interfacefile_1
> 2. use csharps DLLImport directive making a wrapper class i csharp,
> But then I have still two problems
> I. A lot of arguments and return values are of C++ std template types,
> like vector, string etc.
> II. I must create the object in c++ before I can start to use it.
> A solution to both I and II is to make a simpler interface in C++ and
> adding a init function whichs creates the original object when called,
> So then the call stack looks like:
> C++ class I want to use
> C++ wrapper to simplify arguments, and to add a functrion for creation of
> original class
> c wrapper to become compatible with the c# DLL import directive
> a c# wrapper using DLL import
> I know it is possible to skip c wrapper file and using the callnames of
> c++, but since this is not compiler independent I prefer not to do it
> this way.
> So my question is: Is there no easier way to interface to c++ code ?
> Had it only been one class I think I could have used swig, but I donæt see
> how I can use swig when I have many C++ classes.
I use SWIG to wrap hundreds of classes, SWIG comes into its own when
wrapping many C++ classes as it does all the repetitive code generation
for you and has support for std::string and std::vector. When wrapping
one or two small classes, I'd argue it would be easier to do this by
hand than get familiar with SWIG. If you need any help wrapping more
than one class, please ask on the SWIG mailing list
(http://www.swig.org/mail.html) or take a look at the examples shipped
More information about the Mono-devel-list