Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* problem creating .cma library
@ 2009-12-30 17:48 rouanvd
  2009-12-30 23:30 ` [Caml-list] " Guillaume Yziquel
  0 siblings, 1 reply; 21+ messages in thread
From: rouanvd @ 2009-12-30 17:48 UTC (permalink / raw)
  To: caml-list

Hi everyone.

I am trying to create an ocaml binding to a C library as a test to see if I
can get the ocaml FFI to work.  This is just experimental so I can gain
experience to later write bindings to real C libraries for ocaml.

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

I first create a dll called libmylib.dll which contains 1 method called:
void my_print(char* str);

The DLL is created with the MingW toolchan and works correctly as I create
a test C application that links against libmylib.dll and executes correctly.

the library is created with the following gcc commands:

 gcc -fPIC -Wall -c mylib.c
 gcc -shared -o libmylib.dll mylib.o


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) {
    char* str = (char*)String_val( v );
    my_print( str );

    return Val_unit;
}
=======================================

I then create the mylib.ml file which contains the following ocaml code:

=======================================
external my_print : string -> unit = "my_print_stub"
=======================================

I then use the following commands to create a .cma file that is supposed
to expose the my_print function in the libmylib.dll to ocaml:

 ocamlc -c mylib.ml
 ocamlc -c mylib_stub.c

 ocamlmklib -o _stubs mylib_stub.o -L/mingw/lib -L. -lmylib

 ocamlc -a -o mylib.cma mylib.cmo -dllib -l_stubs -ccopt -L. -cclib -lmylib


Up to this point, there are no errors.

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

 "Unbound module Mylib"

The command used to compile the test app is

 ocamlc -verbose mylib.cma -c Main.ml

The Main.ml file contains the following code:

=======================================
open Mylib

let main () =
    my_print "my_print = ok"


main ()
=======================================

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

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

Kind regards
Rouan.


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2010-01-20 14:42 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-30 17:48 problem creating .cma library rouanvd
2009-12-30 23:30 ` [Caml-list] " Guillaume Yziquel
2010-01-05 13:04   ` Damien Doligez
2010-01-08 23:38     ` Guillaume Yziquel
2010-01-08 23:54       ` Basile STARYNKEVITCH
2010-01-09  0:11         ` Guillaume Yziquel
2010-01-09  7:58           ` David Allsopp
2010-01-09 11:33             ` Guillaume Yziquel
2010-01-09 12:52               ` Richard Jones
2010-01-09 14:00                 ` Daniel Bünzli
2010-01-09 14:02                   ` Daniel Bünzli
2010-01-09 14:21                     ` Joel Reymont
2010-01-09 19:36                   ` Guillaume Yziquel
2010-01-10  2:11                     ` Daniel Bünzli
2010-01-11 17:14                       ` Guillaume Yziquel
2010-01-10 13:31                     ` ygrek
2010-01-11 18:01                       ` Guillaume Yziquel
2010-01-09 19:29                 ` Guillaume Yziquel
2010-01-11 12:18                   ` Gerd Stolpmann
2010-01-11 17:11                     ` Guillaume Yziquel
2010-01-20 14:42                   ` Damien Doligez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox