Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's use of cmt file in ocaml?

Tags:

ocaml

I can use option of ocamlc -bin-annot to get a .cmt file,the doc told me it can "Dump detailed information about the compilation (types, bindings, tail-calls, etc) in binary format".

so how to use this .cmt file?I can't find information on web,I think I can go on use the .cmt file got a .cmo file or .out file?but direct use ocamlc test.cmt fail. So how to use the cmt file?Thanks!

like image 768
wang kai Avatar asked Sep 13 '25 01:09

wang kai


1 Answers

The binary annotation files (aka .cmt files) are a binary representation of the typedtree of the files (along with a few more data). Basically, they are meant for tools that want to inspect code without parsing and typing the files themselves.

As an example, I believe the wonderful tool merlin inspects the .cmt files if they are present and uses those to perform its multiple tasks (printing types, auto-completion etc.).

If you are not writing a tool for OCaml, there is no point in trying to use those files. If you are writing a tool, welcome to the wonderful world of the compiler internals, where the documentation is pretty much reading the code.

As far as I know, there is no discussion to make .cmt files compile (though it wouldn't be hard to implement). Mostly, there isn't much of a reason to do it.

like image 118
PatJ Avatar answered Sep 15 '25 19:09

PatJ