在OCaml 4.03.0中,FFI无法使用“未提供实现”错误进行编译

时间:2016-09-26 08:56:37

标签: ocaml ffi

我将ocaml升级到4.03.0。 然后,一些包装器库无法构建提出“没有提供实现”错误。

我准备了一个小例子来解释我的情况。

我在hello_stubs.c

中编写了一个C代码
#include<stdio.h>
#include<caml/mlvalues.h>
CAMLprim value caml_print_hello(value unit)
{
    printf("Hello\n");
    return Val_unit;
}

接下来,我在hello.mli

中为ocaml准备接口文件
external print_hello : unit -> unit = "caml_print_hello"

然后,我在main.ml

中编写主程序
Hello.print_hello();;

为了编译这些程序,我执行了以下命令。

ocamlc -c hello.mli
ocamlc -c hello_stubs.c
ocamlopt -o main main.ml hello_stubs.o

然后,遗憾的是,最后一个命令失败并显示以下错误消息。

File "_none_", line 1:
Warning 58: no cmx file was found in path for module Hello, and its interface was not compiled with -opaque
File "main.ml", line 1:
Error: No implementations provided for the following modules:
         Hello referenced from main.cmx

根据消息, 我试过了ocamlc -opaque hello.mli,但它没有解决问题。

我还确认上面的命令适用于ocaml 4.02.3。

您知道如何使用ocaml 4.03.0编译此示例吗?

1 个答案:

答案 0 :(得分:2)

修复很简单:创建hello.ml相同内容的hello.mli并编译并链接main

我想这是由于4.03.0的以下变化:

  • PR#4166,PR#6956:在调用外部C基元时强制链接 (Jacques Garrigue,Markus Mottl和Christophe Troestler报道)

应更新参考手册的相关部分。见http://caml.inria.fr/mantis/view.php?id=7371