title: How to compile multiple files in OCaml?
body: <p>I am currently teaching myself <code>ocaml</code> for my programming language class and I am having trouble compiling multiple files in <code>ocaml</code>.</p>
  
  <p>I have defined a function in my <code>get_file_buffer.ml</code> file</p>
  
  <p>Source code of <code>get_file_buffer.ml</code></p>
  
  <pre><code>(* 
     Creating a function that will read all the chars 
     in a file passed in from the command argument.
     And store the results in a char list. 
  *)
  
  let read_file char_List =
      let char_in = open_in Sys.argv.(1) in   (* Creating a file pointer/in_channel *)
    try
      while true do
        let c = input_char char_in in         (* Getting char from the file *)
              char_List := c :: !char_List    (* Storing the char in the list *)
      done
    with End_of_file -&gt;
          char_List := List.rev !char_List;   (* End of file was reaching, reversing char list *)
          close_in char_in;                   (* Closing the file pointer/in_channel *)
  
      (* Need to figure out how to catch if the file was not openned. *)
  ;; 
  </code></pre>
  
  <p>I am trying to call the function in my <code>main.ml</code></p>
  
  <p>Source code of <code>main.ml</code></p>
  
  <pre><code>(* Storing the result of read_file to buffer which buffer is a char list reference *)
  let buffer = ref [] in
        Get_file_buffer.read_file(buffer);
  
        print_string "\nThe length of the buffer is: ";
        print_int (List.length !buffer); (* Printing length of the list *)
        print_string ("\n\n");
        List.iter print_char !buffer;    (* Iterating through the list and print each element *)
  </code></pre>
  
  <p>In order to compile the program I am using a <code>MakeFile</code></p>
  
  <p>Makefile content</p>
  
  <pre><code>.PHONY: all
  all: test
  
  #Rule that tests the program
  test: read_test
      @./start example.dat
  
  #Rules that creates executable
  read_test: main.cmx get_file_buffer.cmx
      @ocamlc -o start get_file_buffer.cmx mail.cmx
  
  #Rule that creates main object file
  main.cmx: main.ml
      @ocamlc -c main.ml
  
  #Rule that creates get_file_buffer object file
  get_file_buffer.cmx: get_file_buffer.ml
      @ocamlc -c get_file_buffer.ml
  </code></pre>
  
  <p>When I run the <code>test</code> rule of my <code>Makefile</code> I get the error:
  <code>Error: Unbound module Get_file_buffer</code>.</p>
  
  <p>I have been trying to use these question as references:
  <a href="https://stackoverflow.com/questions/12771674/compiling-multiple-ocaml-files">Compiling multiple Ocaml files</a> and
  <a href="https://stackoverflow.com/questions/28756989/calling-functions-in-other-files-in-ocaml">Calling functions in other files in OCaml</a>.</p>
  
  <p>Yet I have not been able to get the program to compile correctly. How would I correctly compile the above code to make the program run correctly?</p>