Wrapping simple structures with CxxWrap

I’m trying to use CxxWrap, and my C++ library contains a simple structure like this:

struct Address
{
    uint8_t a;
    uint8_t b;
    uint8_t c;
    uint8_t d;
};

Right now I’m getting this problem when I try to compile my bindings:

C++ exception while wrapping module CppHello: No appropriate factory for type 7Address
ERROR: LoadError: No appropriate factory for type 7Address

If I try to add this to the C++ code
mod.add_type<Address>("struct Address");
I get this:

 error: static assertion failed: Mirrored types (marked with IsMirroredType) can't be added using add_type, map them directly to a struct instead and use map_type or explicitly disable mirroring for this type, e.g. define template<> struct IsMirroredType<Foo> : std::false_type { };
   static_assert(!IsMirroredType<T>::value, "Mirrored types (marked with IsMirroredType) can't be added using add_type, map them directly to a struct instead and use map_type or explicitly disable mirroring for this type, e.g. define template<> struct IsMirroredType<Foo> : std::false_type { };");

which is actually an error that is mentioned in the CxxWrap readme. I don’t quite understand, though, what are my alternatives? How do I “wrap them normally” to quote the readme, and how exactly do I use the IsMirroredType?

I ran in the same issue and eventually got it working.
If you want to use map_type, you need to create an equivalent julia structure on the julia side.

mutable struct Address
  a::UInt8
  b::UInt8
  c::UInt8
  d::UInt8
end

This type must be declared before using the @wrapmodule macro

1 Like