autotaker
autotaker

Reputation: 31

In OCaml 4.03.0 FFI fails to compile with "No implementations provided" Error

I upgraded my ocaml to 4.03.0. Then, some wrapper libraries failed to build raising "No implemntations provided" Error.

I prepare a small example to explain my situation.

I write a C code in hello_stubs.c

#include<stdio.h>
#include<caml/mlvalues.h>
CAMLprim value caml_print_hello(value unit)
{
    printf("Hello\n");
    return Val_unit;
}

Next, I prepare the interface file for ocaml, in hello.mli.

external print_hello : unit -> unit = "caml_print_hello"

Then, I code a main program in main.ml

Hello.print_hello();;

To compile these programs, I executed the following commands.

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

Then, unfortunately, the last command failed with the following error message.

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

According to the message, I've tried ocamlc -opaque hello.mli, but it didn't solve the problem.

I also confirmed that the commands above work fine for ocaml 4.02.3.

Do you know how to compile this example with ocaml 4.03.0?

Upvotes: 0

Views: 249

Answers (1)

camlspotter
camlspotter

Reputation: 9040

The fix is easy: create hello.ml of the same contents of hello.mli and compile it and link for main.

I guess this is due to the following change of 4.03.0:

  • PR#4166, PR#6956: force linking when calling external C primitives (Jacques Garrigue, reports by Markus Mottl and Christophe Troestler)

The related section of the reference manual should be updated. See http://caml.inria.fr/mantis/view.php?id=7371

Upvotes: 2

Related Questions