I'm unable to work out how to get SWIG to have a custom destructor for an opaque data type that is managed by the library I'm wrapping.
struct Foo;
Foo* NewFoo();
void UpdateFoo(Foo*);
void DestroyFoo(Foo*);
I've attempted to wrap this in SWIG using:
%module lib
%{
#include "lib.h"
%}
%extend Foo {
~Foo() {
DestroyFoo(self);
}
}
%include "lib.h"
But SWIG warns about Warning 303: %extend defined for an undeclared class Foo.
and fails to generate the destructor for Foo in the resulting wrapper C code.