Version française
Home     About     Download     Resources     Contact us    
Browse thread
problem creating .cma library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Guillaume Yziquel <guillaume.yziquel@c...>
Subject: Re: [Caml-list] problem creating .cma library
rouanvd@softwarerealisations.com a écrit :
> Hi everyone.

Hi.

> I am using ocaml 3.11.0 with the MingW toolchain on windows (vista).

Cannot help you much there.

> Now I create the mylib_stub.c file which contains the marshalling code
> between the libmylib.dll library and ocaml.  This file contains the
> following C code:
> 
> =======================================
> #include <stdio.h>
> #include <caml/mlvalues.h>
> #include "../mylib/mylib.h"
> 
> CAMLprim value
> my_print_stub(value v) {

       CAMLparam1(v);  /* is missing here, for garbage
                          collection purposes. */

>     char* str = (char*)String_val( v );

       /* You do not need the right-hand side (char*) casting. */

>     my_print( str );
> 
>     return Val_unit;
> }

> When I finaly build the test ocaml app which is supposed to use the
> mylib.cma library, ocamlc tells me:
> 
>  "Unbound module Mylib"

Firs of all, mylib.cma is simply an archive of OCaml modules. It may 
contain multiple modules, and might not contain a module called Mylib.

You have to ensure that mylib.cmo is included in mylib.cma. Moreover, 
when you create mylib.cma, you also need a compiled interface, i.e. a 
mylib.cmi file. It's an interface for mylib.cmo. Without it, there's no 
description of module Mylib in mylib.cma.

> The command used to compile the test app is
> 
>  ocamlc -verbose mylib.cma -c Main.ml

You've got something fundamentally wrong here:

Out of main.ml (lower case for the the first letter), you first create a 
main.cmo file. And also a main.mli file with ocamlc -i. You compile the 
main.mli file to main.cmi. Then you create the mylib.cma archive from 
main.cmo and main.cmi.

And mylib.cma will contain the module Main. Not the module Mylib.

> The Main.ml file contains the following code:
> 
> =======================================
> open Mylib
> 
> let main () =
>     my_print "my_print = ok"
> 
> 
> main ()
> =======================================

Here, you're declaring the submodule Mylib of the module Main. Also 
known as Main.Mylib. Not as Mylib.

> Is there a way to verify that the .cma library was created correctly?

There are some tools, such as ocamldumpobj and ocamlobjinfo. Forgot 
which one applies to .cmas.

> I had to install flexlink for ocaml to get the dll linking to work on
> windows.

Can't help you here.

> Kind regards
> Rouan.

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/