What is the best approach to call a C++ function which accepts and returns an Eigen Matrix? The function has signature

```
Eigen::Matrix3Xi makeconvexhull(Eigen::Matrix3Xd points)
```

Here, `points`

is a 3 x N matrix of `double`

and the function returns a M x 3 matrix of integers where every row represents a triangle (i.e. vertex ids of the triangle corresponding to coordinates in `points`

).

- I found
`Polyhedra.jl`

which seems to provide a native Julia code to make convex hulls out of point clouds but I could not understand how to use it. - I already have a C++ code that uses CGAL and Eigen and is specialized for my use case and thus very performant. So I would like to use it preferrably.
- My current approach is to use
`ccall`

which requires me to write a wrapper function in my C++ library that gives a C-style interface to my function.

```
extern "C"{
struct Triangles{
int* firsttriangle;
size_t numtri;
};
Triangles wrapper(size_t N, double* points){
// Use the pointer and size information to make an Eigen matrix
// and forward to the existing function
...
// Take the output of my existing function and convert it to struct Triangles and return
Trianlges triangles;
triangles.firsttriangle = < address of first element of triangle matrix >;
triangles.numtri = < number of triangles >;
return triangles;
}
}
```

Is there a better approach that this?

4. In this approach, I have to do a `malloc()`

in my wrapper function to allocate memory for the output matrix. How do I free this memory from my Julia code once it is not required any more?