title: Compiling C lib and OCaml exe using it, all using ocamlfind
body: <p>I'm trying to work out how to use <code>ocamlfind</code> to compile a C library and an OCaml executable using that C library.</p>
  
  <p>I put together a set of rather silly example files.</p>
  
  <pre><code>% cat sillystubs.c
  #include &lt;stdio.h&gt;
  
  #include &lt;caml/mlvalues.h&gt;
  #include &lt;caml/memory.h&gt;
  #include &lt;caml/alloc.h&gt;
  #include &lt;caml/custom.h&gt;
  
  value
  caml_silly_silly( value unit )
  {
      CAMLparam1( unit );
      printf( "%s\n", __FILE__ );
      CAMLreturn( Val_unit );
  }
  
  % cat silly.mli 
  external silly : unit -&gt; unit = "silly_silly"
  
  % cat foo.ml
  open Silly
  open String
  
  let _ =
      print_string "About to call into silly";
      silly ();
      print_string "Called into silly"
  </code></pre>
  
  <p>I believe the following is the way to compile up the library:</p>
  
  <pre><code>% ocamlfind ocamlc -c sillystubs.c
  % ar rc libsillystubs.a sillystubs.o
  % ocamlfind ocamlc -c silly.mli
  % ocamlfind ocamlc -a -o silly.cma -ccopt -L${PWD} -cclib -lsillystubs
  </code></pre>
  
  <p>Now I don't seem to be able to use the created library though:</p>
  
  <pre><code>% ocamlfind ocamlc -custom -o foo foo.cmo silly.cma
  /usr/bin/ld: cannot find -lsillystubs
  collect2: ld returned 1 exit status
  File "_none_", line 1, characters 0-1:
  Error: Error while building custom runtime system
  </code></pre>
  
  <p>The OCaml tools are somewhat mysterious to me, so any pointers would be most welcome.</p>