2016-08-15 7 views
0

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つの通常の呪文は、両方の私を失敗していると私はアイデアの出だCtypesCtypes.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の上のラッパーだと思う)ocamlfindcorebuild

は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;; 

答えて

4

あなたが実際に実行可能ファイルを構築するために、パッケージからライブラリをリンクコンパイラに指示する-linkpkgはocamlfindオプションを追加することを忘れていることに私には思えます。

関連する問題