Q:

fail to compile ocaml .ml file

I have 4 files: 
A.mli A.ml B.mli B.ml
Using ocamlc -c I have compiled A.mli then A.ml then B.mli with no errors 
How can I use code form files A in B.ml
At the begining of file B.ml I have 
#load "A.cmo"

and this line fails to compile using ocamlc -c
How should I load module(compiled code) in my code?

A:

The #load command only works in the toplevel (the OCaml REPL).
To use code from A.ml in B.ml, you just need to prefix names with A. in the code in B.ml. The compiler will find the compiled version of A.mli and will know what to do.
Later you need to link all the files together to produce an executable. You need to list them in dependency order (a module appears before the other modules that depend on it).
Here's a small example:
$ head a.mli a.ml b.mli b.ml main.ml
==> a.mli <==
val f : int -> int

==> a.ml <==
let f x = x + 10

==> b.mli <==
val g : int -> int

==> b.ml <==
let g x = A.f (x * 10)

==> main.ml <==
let main () = Printf.printf "%d\n" (B.g 12)

let () = main ()
$ ocamlc -c a.mli a.ml b.mli b.ml main.ml
$ ocamlc -o main a.cmo b.cmo main.cmo
$ ./main
130

(There are tools that will automate much of this, which makes OCaml development less tedious. But this should show the basic idea.)

