私はocamlfind
、CライブラリとそのCライブラリを使用してOCaml実行可能ファイルをコンパイルするために使用する方法を理解しようとしています。
かなりばかげたサンプルファイルのセットをまとめました。
% cat sillystubs.c
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
value
caml_silly_silly( value unit )
{
CAMLparam1( unit );
printf( "%s\n", __FILE__ );
CAMLreturn( Val_unit );
}
% cat silly.mli
external silly : unit -> unit = "silly_silly"
% cat foo.ml
open Silly
open String
let _ =
print_string "About to call into silly";
silly ();
print_string "Called into silly"
ライブラリをコンパイルする方法は次のとおりです。
% 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
作成したライブラリを使用できないようですが、次のようになります。
% 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
OCamlツールは私にはやや不思議なので、どんなポインタでも大歓迎です。