OCaml FFIを使ってC enumの幅を推測する方法を理解しようとしていましたが(これはCで定義されていると思います)、am実行時に何が爆発するのかを見るために間違った幅の型を挿入しようとしています。それが動機ですが、私が遭遇した実際の問題ははるかに平凡です。ocamlfindはopam経由でインストールされたモジュールの実装を拒否する
私はC FFIを使用して、enumをintに変換するexample.c
の簡単な関数を呼び出す単純なOCamlファイルを持っています。
open Printf;;
let (@->) = Ctypes.(@->);;
let returning = Ctypes.returning;;
let foreign = Foreign.foreign;;
(* deliberately use the wrong scalar type for argument *)
let wrong_int64_of_color =
foreign "int_of_color" (Ctypes.int64_t @-> returning Ctypes.int64_t);;
let main() =
printf "%Ld\n" (wrong_int64_of_color (Int64.of_int 100));;
let() = main();;
私はopamを設定し、私はシンプルな.ml
スクリプトをコンパイルするために使用する2つの通常の呪文は、両方の私を失敗していると私はアイデアの出だCtypes
とCtypes.Foreign
% opam config env | sed -e 's/=.*/=/'
CAML_LD_LIBRARY_PATH=
OPAMUTF8MSGS=
MANPATH=
PERL5LIB=
OCAML_TOPLEVEL_PATH=
PATH=
% opam list | grep ctypes
ctypes 0.6.2 Combinators for binding to C libraries withou
ctypes-foreign 0.4.0 Virtual package for enabling the ctypes.forei
をインストールしました。 (私はocamlbuild
の上のラッパーだと思う)ocamlfind
とcorebuild
はocamlfindはとforeign
を見つけるように見えることはできません。しかし、私はとctypes.foreign
が奇妙なfindlib
名前空間のこれらのパッケージの正しい名前であると推測しているので、パッケージを見つけることができないということについては不平を言っていません。
% ocamlfind ocamlopt -package findlib,ctypes,ctypes.foreign -thread call_example.ml
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Foreign, and its interface was not compiled with -opaque
File "call_example.ml", line 1:
Error: No implementations provided for the following modules:
Ctypes referenced from call_example.cmx
Foreign referenced from call_example.cmx
ocamlfind
がこれらのモジュールを見つけることができないのはなぜですか?私はトップレベルにそれらをロードする問題はありません。
─(22:30:42)─< command 0
utop # #require "ctypes";;
─(22:30:42)─< command 1
utop # open Ctypes;;
─(22:30:55)─< command 2
utop # #require "ctypes.foreign";;
─(22:31:00)─< command 3
utop # open Ctypes;;