I have 2 native c++ dlls, say A and B. Class X lives in A.dll, and class Y lives in B.dll, with an interface that requires a shared_ptr<X>. I’d like to instantiate X and hand it over to Y using this interface, within a C# app.
Because these two types live in different dlls, I build them separately using swig -dllimport A -c++ -csharp A.i, and swig -dllimport B -c++ -csharp B.i. Within A.i, I’ve used the %shared_ptr(X) macro allowing me to use an object of type X fluidly in all interfaces that require shared_ptr<X> (provided those interfaces are in A.dll).
My problem is, what if class Y in B.dll takes a shared_ptr<X> in it’s interface? How can I make that second swig build, with B.i, aware of shared_ptr<X> (which lives in A.dll)?
What you’re looking for is
%importin SWIG. You can use this as follows, for example with a module test1:Which can be referenced from another module, test2:
What
%importdoes (in an nutshell) is to read the interface, but not generate any wrapper code for it. That is to say it will be aware of the contents of it but not directly output any thing into the wrapper because of it.