ocamlfind抱怨没有为通过opam安装的模块提供实现
我一直在和OCaml FFI打交道,试图弄清楚它是如何推断C枚举的宽度的(我认为这是为C定义的实现),并试图插入一种错误宽度的类型,以查看在运行时发生了什么。这就是动机,但我遇到的实际问题要平凡得多 我有一个简单的OCaml文件,它使用cfi调用ocamlfind抱怨没有为通过opam安装的模块提供实现,ocaml,ocamlfind,Ocaml,Ocamlfind,我一直在和OCaml FFI打交道,试图弄清楚它是如何推断C枚举的宽度的(我认为这是为C定义的实现),并试图插入一种错误宽度的类型,以查看在运行时发生了什么。这就是动机,但我遇到的实际问题要平凡得多 我有一个简单的OCaml文件,它使用cfi调用example.C中的一个普通函数,将枚举转换为int open Printf;; let (@->) = Ctypes.(@->);; let returning = Ctypes.returning;; let foreign = F
example.C
中的一个普通函数,将枚举转换为int
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并安装了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
我用来编译一个简单的.ml
脚本的两个常用咒语都让我失望了,我也没什么主意了ocamlfind
和corebuild
(我认为这是ocamlbuild
之上的包装器)
ocamlfind似乎找不到ctypes
和foreign
。但是,它并不抱怨无法定位包,因此我猜测ctypes
和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
为什么找不到这些模块?我可以将它们加载到顶层
─( 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;;
─( 22:30:42 )─< 命令0
utop需要“ctypes”;;
─( 22:30:42 )─< 命令1
utop#开放Ctypes;;
─( 22:30:55 )─< 命令2
utop需要“ctypes.foreign”;;
─( 22:31:00 )─< 命令3
utop#开放Ctypes;;
在我看来,您似乎忘记添加-linkpkg
ocamlfind选项来指示编译器实际链接来自包的库以构建可执行文件。在我看来,您似乎忘记添加-linkpkg
ocamlfind选项来指示编译器实际链接来自包的库以构建可执行文件可执行文件