From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id DE930BC37 for ; Wed, 30 Dec 2009 20:13:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtoCAM80O0vEGfDtkWdsb2JhbACBSY8UinABAQEBCQsKBxMDRAMBArpjgjuBdgQ X-IronPort-AV: E=Sophos;i="4.47,476,1257116400"; d="scan'208";a="52990179" Received: from rrba-ip-smtp-2-1.saix.net ([196.25.240.237]) by mail4-smtp-sop.national.inria.fr with ESMTP; 30 Dec 2009 20:13:35 +0100 Received: from apu.softwarerealisations.com (dsl-240-166-242.telkomadsl.co.za [41.240.166.242]) by rrba-ip-smtp-2-1.saix.net (Postfix) with ESMTP id C512B2CAC for ; Wed, 30 Dec 2009 21:13:32 +0200 (SAST) Received: from www.softwarerealisations.com (localhost.localdomain [127.0.0.1]) by apu.softwarerealisations.com (8.14.2/8.12.10) with ESMTP id nBUHmo4a008046 for ; Wed, 30 Dec 2009 19:48:51 +0200 Received: from 41.177.16.252 (SquirrelMail authenticated user rouanvd); by www.softwarerealisations.com with HTTP; Wed, 30 Dec 2009 19:48:51 +0200 (SAST) Message-ID: <56670.41.177.16.252.1262195331.squirrel@41.177.16.252> Date: Wed, 30 Dec 2009 19:48:51 +0200 (SAST) Subject: problem creating .cma library From: rouanvd@softwarerealisations.com To: caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Spam: no; 0.00; ocaml:01 ocaml:01 ffi:01 bindings:01 mingw:01 toolchain:01 mingw:01 gcc:01 gcc:01 -fpic:01 -wall:01 mylib:01 -shared:01 mylib:01 stub:01 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 #include #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.