title: Basic Ocaml: How do I compile this?
body: <p>Just beginning with ocaml and am struggling with the various compilers and tooling. E.g. <code>ocamlopt</code>, <code>ocamlc</code>, <code>ocamlbuild</code>, <code>corebuild</code> and so on.  So, how do I compile the following?</p>
  
  <pre><code>open Core.Std
  
  module Regex = Re2.Regex
  
  let ls pattern = 
    let pat = Regex.create_exn pattern in
    let matcher = Regex.matches pat in
    Sys.ls_dir "." 
    |&gt; List.filter ~f:matcher
    |&gt; List.iter ~f:(fun s -&gt; print_string s; print_newline ())
  
  let () =
    match In_channel.input_line stdin with
    | None -&gt; print_string "No Input"
    | Some pat -&gt; ls pat
  </code></pre>
  
  <p>In <code>utop</code> I can just <code>#require "re2"</code> and go from there.  </p>
  
  <p>Without the inclusion of the regular expressions module I would just use <code>corebuild ls.native</code>, assuming that the above code is placed into <code>ls.ml</code>.    </p>
  
  <p>[edit]</p>
  
  <p>Have so far tried</p>
  
  <p><code>ocamlbuild -use-ocamlfind -package core -package re2</code>  </p>
  
  <p>which spit out</p>
  
  <pre><code>ocamlfind ocamldep -package core -package re2 -modules ls.ml &gt; ls.ml.depends
  ocamlfind ocamlc -c -package core -package re2 -o ls.cmo ls.ml
  + ocamlfind ocamlc -c -package core -package re2 -o ls.cmo ls.ml
  ocamlfind: Error from package `threads': Missing -thread or -vmthread switch
  Command exited with code 2.
  </code></pre>
  
  <p>So after some googling I was led to <a href="http://gallium.inria.fr/blog/quick-tip-the-ocamlbuild-documentation-option/" rel="nofollow">this blog</a> I tried</p>
  
  <p><code>ocamlbuild -tag thread -use-ocamlfind -package core -package re2</code></p>
  
  <p>which spits out over 6000 lines of what looks like <code>make</code> output before failing with:</p>
  
  <pre><code>collect2: error: ld returned 1 exit status
  File "caml_startup", line 1:
  Error: Error during linking
  Command exited with code 2.
  </code></pre>
  
  <p>so I'm not sure what to try next.</p>