Casting a Ctype pointer to an abstract type

I have two libraries, one which uses Ctypes and another which does FFI directly and I would like to pass values between them.

module Ct = struct
  type t = unit ptr
  let foo : unit -> t = ...
end

module Fi = struct
   type t
  external bar : t -> ...  = ...
end

The underlying data structures managed by both libraries are the same. How can I cast a Ct.t to a Fi.t?

The underlying data structures managed by both libraries are the same.

there is nothing on the ocaml side to prove that, so it seems in the end you will need smth like external cast : nativeint -> Fi.t and Ctypes.raw_address_of_ptr : unit ptr -> nativeint

I was trying to avoid having to write a manual cast function in C.

But it looks like I can abuse the Ctypes.Root.get function for this.