Rella Rella - 4 months ago 46
C Question

How to port OCaml lib into a lib accessible from C code?

I have a OCaml library with lots of classes I need some translator to make it from OCaml lib a C lib so to be able to use its methods. How to do such thing? How to port OCaml lib into lib Acsessable from C code?


Generally porting from one language to another is a very manual process. You read through the original source and convert it, largely by hand, to the new language. There may be tools to help you out along the way, but you're still going to need to get your hands dirty a lot.

That said, it's possible to call OCaml functions from a C program (and vice versa). This will still require writing a bunch of code but might prove to be easier (you only need to understand the library, not how the library works).

Here is a blog post on how to do this. In addition to that blog post, you can check out the official docs, which focus far more on calling C code from OCaml (the opposite of what you want to do). That can be found here.

There is also a chapter in the O'Reilly book on this.