Creating a custom data type for CxxWrap

I’m trying to write a wrapper for a C++ library using CxxWrap.jl.

In C++, there are types like

typedef struct {
  int MyType;
  int *List;
} MyRecord

typedef MyRecord *MyPointer;
typedef MyPointer *MyList;

To create Julia counterparts, I did

mutable struct MyRecord
  MyType::Cint
  List::Ref{Cint}
end

MyPointer = Ref{MyRecord}
MyList = Ref{MyPointer}

Is this how I am supposed to do? It seems not. I still get an “No appropriate factory for type” error.

You don’t need to create the Julia classes. CxxWrap does that for you.
Conceptually, you write the wrapper code in C++ and compile a library. Your Julia module then just imports that library; there is no other code needed on the Julia side.

The documentation is a bit dense, but there’s a fairly simple example that comes with the package. You may have to copy it out of a file with other examples, but there are fairly small examples and tests.

PS: if your struct contains custom types, you’ll need to wrap those, too

1 Like

@jstrube Thanks! I managed to learn many things from the examples.